2012-10-19 51 views
2

我想使用的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的測試,我將感謝任何意見。

+0

這是自我解釋爲調用_ [** **選擇器presentViewController:** **選擇器動畫:否完成:無]; _(參照粗部分)。你可以不叫選擇器來呈現選擇器(即自己同類型的UIViewController同一類我的意思是)模態因爲都是相同的LOL :) –

+0

嘿嘿..權完全以錯過。但是爲什麼在所有例子中他們都以這種方式使用它? – BW4

+0

請問你給我的鏈接哪個例子你遵循,所以我可以解釋,也是:) –

回答

0

我發現,在這一刻,茯苓有一定的問題與iOS6和portrain方向。 ImagePickerController只能在portrain中工作,所以這是崩潰的原點。我會監測這個案例,並在有些事情會發生變化時進行更新。

+0

我的意見你有沒有解決這個問題? –

2

更改代碼,如下只是改變了符合Edit in this line評論或可以複製過去該行

-(void)pickPhoto:(UIImagePickerControllerSourceType)sourceType{  
    UIImagePickerController *picker = [[UIImagePickerController alloc]init]; 
    picker.delegate = self; 
    picker.sourceType = sourceType; 
    picker.wantsFullScreenLayout = YES; 
    [self presentViewController:picker animated:NO completion:nil]; //Edit in this line 
    [[[CCDirector sharedDirector] view] addSubview:picker.view]; 
} 

-(void)imagePickerController:(UIImagePickerController *)picker 
     didFinishPickingMediaWithInfo:(NSDictionary *)info{ 
    newImage = [info objectForKey:@"UIImagePickerControllerOriginalImage"]; 
    [self dismissViewControllerAnimated:YES completion:nil]; //Edit in this line 
    [picker.view removeFromSuperview]; 
    [picker release]; 
    CCSprite *imageFromPicker = [CCSprite spriteWithCGImage:newImage.CGImage key:@"ImageFromPicker"]; 
} 
+0

可悲的'實例方法'-presentViewController:animated:completion:'not found ' – BW4

+0

見上 –