ios - Cocos2d Xcode - SLComposeViewController 黑屏

标签 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,但在显示时,我得到了黑色背景,在我点击发布或取消后,屏幕保持黑色。我正在考虑将 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/

相关文章:

ios - iOS YouTube YouTube API上传视频,如何记录错误的userInfo?

ios - animateWithDuration 在 vi​​ewWillAppear ios 9 objective-c 中不起作用

ios - FBRequestConnection 不工作

ios - 为什么 UISearchBar tableview 索引路径总是返回 objectAtIndex :0

iOS - Apple App 沙盒不适用?

iphone - 当稍后需要引用传递给类中函数的 NSString 时,正确的方法是什么? (iPhone 开发者)

ios - 平台有问题吗? (Cocos2D)

单一语言的 iOS 应用本地化

ios - UITableView 以编程方式未显示

ios - 在 tvOS 应用程序中使用 iOS 框架