2013-09-23 45 views
3

我的弹窗大小在iOS 7中大小不正确。高度工作正常,但宽度没有设置。无论我设置的是什么,popover的宽度都很小。它仍然可以在iOS 6中运行,但在iOS 7中可以运行。7中有没有新的东西需要处理,我失踪了?UIPopoverController宽度未设置

下面是iOS中工作6,而不是适用于iOS 7的代码:

self.mediaPicker = [[UIImagePickerController alloc] init]; 

self.mediaPicker.contentSizeForViewInPopover = CGSizeMake(self.view.frame.size.width, self.view.frame.size.height);  
self.cameraPickerPopover = [[UIPopoverController alloc] initWithContentViewController:self.mediaPicker];  
self.cameraPickerPopover.popoverContentSize = CGSizeMake(self.view.frame.size.width, self.view.frame.size.height); 
self.cameraPickerPopover.delegate = self; 
[self.cameraPickerPopover presentPopoverFromRect:self.toolbar.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:animated]; 

我发现contentSizeForeViewInPopover在iOS的7弃用,所以我更新的代码如下所示,仍然没有工作:

if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) { 
    self.mediaPicker.contentSizeForViewInPopover = CGSizeMake(self.view.frame.size.width, self.view.frame.size.height);  
} else { 
    self.mediaPicker.preferredContentSize = CGSizeMake(self.view.frame.size.width, self.view.frame.size.height); 
} 

回答

4

答案在这里提供

How to change the size width of UIImagePickerController on iPad?

是正确的,除了iOS 7,contentSizeForViewInPopover属性应该由preferredContentSize属性替换。

UIImagePickerController的委托实现了UIImagePickerControllerDelegate和UINavigationControllerDelegate协议。

添加在委托执行下面的方法解决了的iOS 7的问题,对我来说:

- (void)navigationController:(UINavigationController*)navigationController willShowViewController:(UIViewController*)viewController animated:(BOOL)animated 
{ 
    if (SYSTEM_VERSION_GREATER_THAN(@"7.0")) 
    viewController.preferredContentSize = CGSizeMake(800,800); 
    else 
    viewController.contentSizeForViewInPopover = CGSizeMake(800, 800); 
}