我想使用的UIImagePickerController,我發現這個例子的UIImagePickerController與cocos2d的2.0
加入的.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的測試,我將感謝任何意見。
這是自我解釋爲調用_ [** **選擇器presentViewController:** **選擇器動畫:否完成:無]; _(參照粗部分)。你可以不叫選擇器來呈現選擇器(即自己同類型的UIViewController同一類我的意思是)模態因爲都是相同的LOL :) –
嘿嘿..權完全以錯過。但是爲什麼在所有例子中他們都以這種方式使用它? – BW4
請問你給我的鏈接哪個例子你遵循,所以我可以解釋,也是:) –