适用于iPhone 6 Plus的UIModalPresentationPopover不会显示popup窗口
我想始终在所有设备和所有方向上的popup窗口中显示ViewController
。 我尝试通过采用UIPopoverPresentationControllerDelegate
并设置sourceView
和sourceRect
来完成此sourceRect
。
这对于所有设备和方向都非常有效,除了横向的iPhone 6 Plus。 在这种情况下,视图控制器从表单的屏幕底部向上滑动。 我怎样才能防止它,以便它总是会出现在popover?
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { let popoverPresentationController = segue.destinationViewController.popoverPresentationController popoverPresentationController?.delegate = self popoverPresentationController?.sourceView = self.titleLabel!.superview popoverPresentationController?.sourceRect = self.titleLabel!.frame } func adaptivePresentationStyleForPresentationController(controller: UIPresentationController) -> UIModalPresentationStyle { return UIModalPresentationStyle.None }
所有设备都在iOS 8.2或更高版本
实现adaptivePresentationStyleForPresentationController:traitCollection:
的新的adaptivePresentationStyleForPresentationController:traitCollection:
方法:
- (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller traitCollection:(UITraitCollection *)traitCollection { // This method is called in iOS 8.3 or later regardless of trait collection, in which case use the original presentation style (UIModalPresentationNone signals no adaptation) return UIModalPresentationNone; }
UIModalPresentationNone
告诉演示控制器使用原来的演示风格,在你的情况下会显示一个popup窗口。
苹果公司根据其尺寸等级devise了iPhone 6 Plus演示。
要阻止iPhone 6 Plus上的模式呈现,您必须重写特征集合(水平大小)。
您应该能够为演示文稿控制器设置overrideTraitCollection
属性:
presentedVC.presentationController.overrideTraitCollection = [UITraitCollection traitCollectionWithHorizontalSizeClass:UIUserInterfaceSizeClassCompact];
(对不起,目标C!我还没学到Swift。)
在Swift 3中,如果您实现了原始的adaptivePresentationStyle
方法,只需添加此代码就可以工作:
func adaptivePresentationStyle(for controller: UIPresentationController, traitCollection: UITraitCollection) -> UIModalPresentationStyle { return adaptivePresentationStyle(for: controller) }