我有一个我一直在开发的 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,但在显示时,我得到了黑色背景,在我点击发布或取消后,屏幕保持黑色。我正在考虑将 rootViewController 设置为 HighScores,但鉴于它不是 ViewController,我无法做到这一点。
最佳答案
我现在没有代码,但我相信过去我创建了 SLComposeViewController 并将其添加为类似于以下的 subview :
[[[CCDirector sharedDirector] openGLView] addSubView:controller.view];
要删除它,您必须删除 subview 。您也可以尝试:
AppController* app = (AppController*) [[UIApplication sharedApplication] delegate];
[[app navController] presentModalViewController:controller animated:YES];
关于ios - Cocos2d Xcode - SLComposeViewController 黑屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22038986/