UIModalPresentationPopover for iPhone 6 Plus在横向上不显示弹出窗口

Loe*_*gic 32 iphone ios uimodalpresentationstyle ios8 iphone-6-plus

我想总是ViewController在所有设备和所有方向上提供一个popover.我试图通过采用UIPopoverPresentationControllerDelegate和设置sourceView和来完成这个sourceRect.

这适用于所有设备和方向,除了横向的iPhone 6 Plus.在这种情况下,视图控制器在表单中从屏幕底部向上滑动.如何防止它始终出现在弹出框中?

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 }
Run Code Online (Sandbox Code Playgroud)

所有设备均在iOS 8.2或更高版本下

Jos*_*hua 74

实施新adaptivePresentationStyleForPresentationController:traitCollection:方法UIAdaptivePresentationControllerDelegate:

- (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;
}
Run Code Online (Sandbox Code Playgroud)

UIModalPresentationNone 告诉演示控制器使用原始演示样式,在您的情况下将显示弹出窗口.

  • 由于某种原因,我花了三次读取才最终看到该委托方法的:traitCollection部分.我最初想,"是的,我已经实现了",因为较短的版本适用于其他设备.谢谢!...我一直在撞墙,为什么它不适合6岁以上.这总是最简单的事情. (10认同)
  • 为什么Apple会对6/7 Plus的景观进行此特定更改?为什么不显示一个弹出窗口,如果这是你要求的? (2认同)

JKa*_*Kaz 5

在Swift 3中,如果您实现了原始adaptivePresentationStyle方法,只需添加以下代码即可:

func adaptivePresentationStyle(for controller: UIPresentationController, traitCollection: UITraitCollection) -> UIModalPresentationStyle {
    return adaptivePresentationStyle(for: controller)
}
Run Code Online (Sandbox Code Playgroud)