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를의보기를 포함 할 수 있습니다.

- (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]; 
    } 
} 

희망이

편집을하는 데 도움이 : 어떤 이상한 이유로, 프레임이 실제로 때 가로 오른쪽으로 변경 않습니다.

이 문제를 해결하려면 popover를 제시 한 후 이미지 선택 도구의보기 프레임을 설정해야합니다.

나는 이것을 보여주기 위해 위의 코드를 편집했다.

또한, 컨트롤러,이 추가 :

나는 Mutix의 솔루션을 시도
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { 

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

감사합니다. 어쨌든 iPad 컨테이너의 너비와 높이를 얻을 수 있습니까? containerController.contentSizeForViewInPopover = CGSizeMake (768, 1000); ? – GuybrushThreepwood

+0

ipad 해상도는 768x1024입니다. popover가 전체 화면을 차지하게하려면 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]; 

는 또한, 내가 가로 모드에 대한 특별한 처리를 필요로하지 않았다.

관련 문제