Cocos2d 2.1 - 如何在CCLayer中显示UIImagePicker视图控制器?

时间:2013-11-18 02:00:53

标签: iphone objective-c cocos2d-iphone

我使用的是Cocos2d 2.1。最新稳定。我已经阅读了与此问题相关的其他一些帖子,但我怀疑他们可能正在使用旧版本的Cocos2d。我有一个MenuLayer(CCLayer),我想呈现UIImagePicker视图。以下是我目前正在尝试的内容:

-(void)pickPhoto{
UIImagePickerController *picker = [[UIImagePickerController alloc]init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
picker.wantsFullScreenLayout = YES;
[self presentModalViewController:picker animated:NO];
[[[CCDirector sharedDirector] view] addSubview:picker.view];

}

应用程序因以下错误而崩溃:

  

- [MenuLayer presentModalViewController:animated:]:无法识别的选择器发送到实例0x89768f0

所以CCLayer不能是UIViewController。有人能说出如何在CCLayer中正确显示UIImagePicker吗?

谢谢!

2 个答案:

答案 0 :(得分:0)

我知道了。

此解决方案有效:

-(void)pickPhoto{
UIImagePickerController *picker = [[UIImagePickerController alloc]init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
picker.wantsFullScreenLayout = YES;
[[[CCDirector sharedDirector] view] addSubview:picker.view];
}

答案 1 :(得分:0)

presentModalViewController是来自UIViewController的方法。您只能将此方法称为从UIViewController继承的类。但是在你的情况下,MenuLayer不是从UIViewController继承的。如果要呈现视图控制器,则应使用CDDirector类。

   [[CCDirector sharedDirector] presentModalViewController:picker animated:YES];