UIModalPresentationPopover for iPhone 6 Plus in landscape doesn't display popover

房东的猫 提交于 2019-11-30 16:51:24

Implement the new adaptivePresentationStyleForPresentationController:traitCollection: method of 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;
}

UIModalPresentationNone tells the presentation controller to use the original presentation style which in your case will display a popover.

In Swift 3, if you implemented the original adaptivePresentationStyle method, simply adding this code works:

func adaptivePresentationStyle(for controller: UIPresentationController, traitCollection: UITraitCollection) -> UIModalPresentationStyle {
    return adaptivePresentationStyle(for: controller)
}

Apple designed the iPhone 6 Plus presentation to behave that way, based on its size class.

To prevent the modal presentation on the iPhone 6 Plus, you'll have to override the trait collection (horizontal size).

You should be able to set the overrideTraitCollection property for the presentation controller:

presentedVC.presentationController.overrideTraitCollection = [UITraitCollection traitCollectionWithHorizontalSizeClass:UIUserInterfaceSizeClassCompact];

(Sorry for the Objective C! I haven't learned Swift yet.)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!