我希望在所有设备和方向上始终以弹出视图控制器的形式呈现。我尝试通过采用UIPopoverPresentationControllerDelegate并设置sourceView和sourceRect来实现此目的。故事板中的segue被配置为Present As Popover segue。这对于所有设备和方向都非常有效,除了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
}
traitCollection
的方法未在文档中列出。但不幸的是,这对我没有用,因为在 iPhone 6 Plus 横向时它没有调用该方法,但在旋转时确实调用了该方法。在纵向时,它在呈现时确实调用了该方法,但返回.None
会导致呈现方式为 Over Full Screen 而不是弹出窗口。 - Jordan HpopoverPresentationController
的委托解决了问题。 - Jordan H