4

私はUIPopOverを使ってプレゼンテーションしているUIImagePickerのサイズを変更しようとしています。コードを以下に示します。 PopOverのサイズが正しく表示されないという問題があります。ポップオーバーのサイズが短時間、正しいサイズで点滅してから、通常のデフォルトサイズにアニメートされます。UIPopOver(iPad)で表示されるUIImagePickerのサイズを変更する

私はどのように私がポップオーバーのサイズを変更することができますか?私はこれが最もエレガントな解決策であるかわからない

- (void)showImagePickerForPhotoLibrary { 
    NSLog(@"Picker"); 
    imagePickerController = [[UIImagePickerController alloc] init]; 
    imagePickerController.delegate = self; 
    imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; 
    imagePickerController.contentSizeForViewInPopover = CGSizeMake(768, 1000); 

    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { 
     Class cls = NSClassFromString(@"UIPopoverController"); 
     if (cls != nil) { 
      popoverController = [[UIPopoverController alloc] initWithContentViewController:imagePickerController]; 
      //popoverController.popoverContentSize = CGSizeMake(768, 1000); 
      [popoverController presentPopoverFromRect:selectedRect inView:self.view permittedArrowDirections:4 animated:YES]; 
     } 
    } 
    else { 
     [app.mainViewController presentModalViewController:imagePickerController animated:YES]; 
    } 
} 

答えて

10

は、しかし、私のために正常に動作するようです:

あなたは「コンテナ」のUIViewControllerのビューにUIImagePickerControllerのビューを埋め込むことができます。風景の右にあるいくつかの奇妙な理由で、フレームが実際に変化しない:これは

EDITを助け

- (void)showImagePickerForPhotoLibrary { 
NSLog(@"Picker"); 
    imagePickerController = [[UIImagePickerController alloc] init]; 
    imagePickerController.delegate = self; 
    imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; 

    UIViewController *containerController = [[UIViewController alloc] init]; 
    containerController.contentSizeForViewInPopover = CGSizeMake(768, 1000); 

    [containerController.view addSubview:imagePickerController.view]; 

    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { 
     Class cls = NSClassFromString(@"UIPopoverController"); 
     if (cls != nil) { 
      popoverController = [[UIPopoverController alloc] initWithContentViewController:containerController]; 

      [popoverController presentPopoverFromRect:selectedRect inView:self.view permittedArrowDirections:4 animated:YES]; 


      [imagePickerController.view setFrame:containerController.view.frame]; 
     } 
    } 
    else { 
     [app.mainViewController presentModalViewController:containerController animated:YES]; 
    } 
} 

希望。

この問題を解決するには、ポップオーバーを提示した後でイメージピッカーのビューフレームを設定する必要があります。

これを示すために上記のコードを編集しました。

また、お使いのコントローラでは、この追加:私はMutixのソリューションを試したとき

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { 

    [imagePickerController.view setFrame:imagePickerController.view.superview.frame]; 
} 
+0

ありがとうございました。とにかくiPadの幅と高さをcontainerController.contentSizeForViewInPopover = CGSizeMake(768,1000)という行で取得できますか? ? – GuybrushThreepwood

+0

ipadの解像度は768x1024です。 CGSizeMake(self.view.frame.size.width、self.view.frame.size.height)を試してみてください – Mutix

+0

この種の作品ですが、別の(奇妙な)バグが発生します:http ://stackoverflow.com/questions/8422636/black-bar-in-uiimagepicker-on-ipad-only-in-landscape-right-orientation – GuybrushThreepwood

0

をポップオーバーは、空の白いビューでだけでナビゲーションバーを示しました。

私の周りの方法は、pickerのビューを追加するだけでなく、containerControllerの子としてimagePickerControllerを追加することでした。これらの行で

[containerController.view addSubview:imagePickerController.view]; 

は、主に、それは、この行を置き換えることを意味し、このアプローチを使用するとき

[containerController addChildViewController:imagePickerController]; 
[containerController.view addSubview:imagePickerController.view]; 
[imagePickerController didMoveToParentViewController:containerController]; 

はまた、私は風景モードのための特別な処理を必要としませんでした。

関連する問題