我想使用 UIImagePickerController,我找到了这个例子
添加到 .h
@interface MenuScene : CCLayer <UIImagePickerControllerDelegate, UINavigationControllerDelegate>
{
UIWindow *window;
UIImage *newImage;
}
添加到 .m
-(void)pickPhoto:(UIImagePickerControllerSourceType)sourceType{
UIImagePickerController *picker = [[UIImagePickerController alloc]init];
picker.delegate = self;
picker.sourceType = sourceType;
picker.wantsFullScreenLayout = YES;
[picker presentViewController:picker animated:NO completion:nil];
[[[CCDirector sharedDirector] view] addSubview:picker.view];
}
-(void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info{
newImage = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
[picker dismissViewControllerAnimated:YES completion:nil];
[picker.view removeFromSuperview];
[picker release];
CCSprite *imageFromPicker = [CCSprite spriteWithCGImage:newImage.CGImage key:@"ImageFromPicker"];
}
我尝试打电话,但它在消息[self pickcPhoto:UIImagePickerControllerSourceTypeCamera]
中崩溃[picker presentViewController:picker animated:NO completion:nil];
由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“应用程序试图在自身上呈现模态视图控制器。呈现控制器是 . '
我在 iOS 6 上使用 Cocos2d v2 测试,如果有任何建议,我将不胜感激。