我想始终在所有设备和所有方向上的弹出窗口中显示一个 ViewController
。我试图通过采用 UIPopoverPresentationControllerDelegate
并设置 sourceView
和 sourceRect
来实现这一点。
这适用于所有设备和方向,除了横向的 iPhone 6 Plus。在这种情况下, View Controller 会在表单中从屏幕底部向上滑动。我怎样才能防止它始终出现在弹出窗口中?
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 或更高版本下
最佳答案
实现 UIAdaptivePresentationControllerDelegate
的新 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
告诉呈现 Controller 使用原始呈现样式,在您的情况下将显示弹出窗口。
关于ios - 横向 iPhone 6 Plus 的 UIModalPresentationPopover 不显示弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30378249/