我已经开发了一个Cocos2d游戏,通过在屏幕上创建这样一个按钮,我成功地让它呈现了一个SLComposeViewController:
头文件如下所示:
@interface HighScores : Main
@end
@interface socialViewControllerAtTheBottomOfThisClass : UIViewController
@end.m文件中的代码:
@implementation HighScores
- (init) {
UIButton *shareButton = [[UIButton alloc] initWithFrame:CGRectMake(screenWidth/2, screenHeight/2, 100, 30)];
[shareButton addTarget:self action:@selector(shareAction) forControlEvents:UIControlEventTouchUpInside];
}
- (void)shareAction {
// I created a ViewController class at the end of the .m file containing the social stuff
// but I did this and managed to get it to present the SLComposeViewController:
socialViewControllerAtTheBottomOfThisClass *bottomController = [[socialViewControllerAtTheBottomOfThisClass alloc] init];
[[[[CCDirector sharedDirector] openGLView] window] setRootViewController:bottomController];
[bottomController shareToFacebook];
}
}
@end然后在ViewController实现的底部:
@implementation socialViewControllerAtTheBottomOfThisClass
- (void)shareToFacebook {
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[controller setInitialText:@"This is my facebook status!"];
[self presentViewController:controller animated:YES completion:nil];
controller.completionHandler = ^(SLComposeViewControllerResult result) {
switch(result) {
case SLComposeViewControllerResultCancelled: [self actionForCancelled];
break;
case SLComposeViewControllerResultDone: [self actionForDone];
break;
}};
}
}
- (void)actionForCancelled {
}
- (void)actionForDone {
}
@end代码显示SLComposeViewController,但是在演示时,我会得到一个黑色的背景,在我点击Post或Cancel之后,屏幕将保持黑色。我正在考虑将rootViewController设置为HighScores,但考虑到它不是ViewController,我无法做到这一点。
发布于 2014-02-26 17:32:50
我现在没有代码,但我相信在过去,我创建了SLComposeViewController并将其添加为类似于以下的子视图:
[[[CCDirector sharedDirector] openGLView] addSubView:controller.view];要删除它,您必须删除子视图。你也可以尝试:
AppController* app = (AppController*) [[UIApplication sharedApplication] delegate];
[[app navController] presentModalViewController:controller animated:YES];https://stackoverflow.com/questions/22038986
复制相似问题