0
我有一个cocos2d的游戏,我一直在努力,我已经成功地得到它通过创建一个按钮在屏幕上像这样为呈现SLComposeViewController
:的cocos2d的Xcode - 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
然后在底部的视图控制器实现:
@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,我无法做到这一点。
我已经设法通过运行[[CCDirector shareDirector] replaceWithScene:[Game scene]]来显示白色屏幕; – iOSDec
不要更改根视图控制器。试试像在[[CCDirector sharedDirector] openGLView]上的其他视图控制器一样呈现它。 –
试过这个家伙,我的Cocos2d版本老了 - 所以要做到这一点我必须做的:[[[CCDirector sharedDirector] openGLView] window] rootViewController] presentViewController:controller animated:YES completion:nil]; 但由于某种原因,它不会呈现它?任何想法哈哈? – iOSDec