我不确定这是最优雅的解决方案,但它似乎对我来说很好:
您可以将UIImagePickerController的视图嵌入到"容器"UIViewController的视图中.
- (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]; } }
希望这可以帮助
编辑:由于一些奇怪的原因,框架确实在景观正确时改变.
为了解决这个问题,您需要在显示弹出窗口后设置图像选择器的视图框架.
我已经编辑了上面的代码来展示这个.
此外,在您的控制器中,添加以下内容:
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { [imagePickerController.view setFrame:imagePickerController.view.superview.frame]; }