2011-08-28 13 views
9

UIActionSheetの結果に応じて、次の機能を使用してデバイスカメラまたは画像ピッカーをアクティブにしています。 fromCamera = YESの場合、iPhoneとiPadの両方で動作します。 fromCamera = NOの場合はiPhone上で動作し、画像ピッカーが表示されます。しかし、次のエラーでiPad上でクラッシュします。このデバイスではUIStatusBarStyleBlackTranslucentを利用できません。私はすでにiPadがUIStatusBarStyleBlackTranslucent statusBarを表示できないことを知っていますが、このクラッシュを避けるにはどうすればいいですか?クラッシュiPadフォトピッカー

-(void)addPhotoFromCamera:(BOOL)fromCamera{ 

if(fromCamera){  
    picker.sourceType = UIImagePickerControllerSourceTypeCamera; 
} 
else{ 
    picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; 
} 


[self presentModalViewController:picker animated:YES]; 

}

+0

確かに誰かがiPadでUIImagePickerControllerSourceTypePhotoLibraryを使用しましたか? – wasabi

答えて

3

私はUIImagePickerがあなたのInfo.plistファイルからか、現在表示されているビューコントローラから半透明のステータスバーを継承している疑いがあります。

アプリを半透明のステータスバーにしないとどうなりますか?私は同様の問題を抱えていた

4

を使用すると、iPadでUIImagePickerControllerSourceTypePhotoLibraryにピッカーを設定した場合、あなたはpopoverviewにそれを提示しなければなりません(!)それ以外の場合は例外が発生します。

-(void)openPhotoPicker 
{ 
    imagePicker = [[UIImagePickerController alloc] init]; 
    imagePicker.delegate = self; 
    imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; 
    imagePicker.navigationBar.opaque = true; 

    //put the image picker in its own container controller, to control its size 
    UIViewController *containerController = [[UIViewController alloc] init]; 
    containerController.contentSizeForViewInPopover = rightPane.frame.size; 
    [containerController.view addSubview:imagePicker.view]; 

    //then, put the container controller in the popover 
    popover = [[UIPopoverController alloc] initWithContentViewController:containerController]; 

    //Actually, I would like to do the following, but iOS doesn't let me: 
    //[rightPane addSubview:imagePicker.view]; 

    //So, put the popover over my rightPane. You might want to change the parameters to suit your needs. 
    [popover presentPopoverFromRect:CGRectMake(0.0, 0.0, 10.0,0.0) 
        inView:rightPane 
    permittedArrowDirections:UIPopoverArrowDirectionLeft 
        animated:YES]; 

    //There seems to be some nasty bug because of the added layer (the container controller), so you need to call this now and each time the view rotates (see below) 
    [imagePicker.view setFrame:containerController.view.frame]; 
} 

私も回転のバグに対処するには、次のようにあります:

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { 
    if(imagePicker!=nil && rightPane.frame.size.width>0) 
     [imagePicker.view setFrame:imagePicker.view.superview.frame]; 
} 
私はポップオーバーのサイズを(標準サイズは私の意見では小さすぎる)を制御する少なくともまで、このようにそれを行います

これは完璧ではありませんが、現時点でテスト目的では問題ありません。私はPopoverviewを使用することを余儀なくされるのが好きではないので、私自身のImagepickerを書くことを検討します...しかし、まあ、それは別の話です。