UIModalPresentationPopover for iPhone 6 Plus在横向上不会显示弹出窗口 [英] UIModalPresentationPopover for iPhone 6 Plus in landscape doesn't display popover

查看:481
本文介绍了UIModalPresentationPopover for iPhone 6 Plus在横向上不会显示弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在所有设备和所有方向的弹出窗口中始终显示 ViewController 。我尝试通过采用 UIPopoverPresentationControllerDelegate 并设置 sourceView sourceRect

I want to always present a ViewController in a popover on all devices and all orientations. I tried to accomplish this by adopting the UIPopoverPresentationControllerDelegate and setting the sourceView and sourceRect.

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

This works very well for all devices and orientations, except the iPhone 6 Plus in landscape. In that case the view controller slides up from the bottom of the screen in a form sheet. How can I prevent that so that it will always appear in a 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或更高版本下

All device are under iOS 8.2 or higher

推荐答案

实现新的 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;
}

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

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

这篇关于UIModalPresentationPopover for iPhone 6 Plus在横向上不会显示弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆