Cocos2d Xcode - SLComposeViewController黑屏

时间:2014-02-26 10:46:22

标签: ios objective-c cocos2d-iphone

我有一个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,我无法做到。

1 个答案:

答案 0 :(得分:2)

我目前没有代码,但我相信在过去我创建了SLComposeViewController并将其添加为类似于的子视图:

[[[CCDirector sharedDirector] openGLView] addSubView:controller.view];

要删除它,您必须删除子视图。您也可以尝试:

AppController* app = (AppController*) [[UIApplication sharedApplication] delegate];
[[app navController] presentModalViewController:controller animated:YES];