为 iPhone 6 Plus 横向设置 UIModalPresentationStyle?
Setting UIModalPresentationStyle for iPhone 6 Plus in landscape?
我想始终在所有设备和所有方向上的弹出窗口中显示一个视图控制器。我试图通过采用 UIPopoverPresentationControllerDelegate
并设置 sourceView
和 sourceRect
来实现这一点。故事板中的转场被配置为 Present As Popover 转场。这适用于所有设备和方向,除了横向的 iPhone 6 Plus。在这种情况下,视图控制器以 sheet 的形式从屏幕底部向上滑动。我怎样才能防止它始终出现在弹出窗口中?
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
}
实施 UIAdaptivePresentationControllerDelegate
的新方法(从 iOS 8.3 开始)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
告诉呈现控制器使用原始呈现样式,在您的情况下将显示弹出窗口。
我想始终在所有设备和所有方向上的弹出窗口中显示一个视图控制器。我试图通过采用 UIPopoverPresentationControllerDelegate
并设置 sourceView
和 sourceRect
来实现这一点。故事板中的转场被配置为 Present As Popover 转场。这适用于所有设备和方向,除了横向的 iPhone 6 Plus。在这种情况下,视图控制器以 sheet 的形式从屏幕底部向上滑动。我怎样才能防止它始终出现在弹出窗口中?
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
}
实施 UIAdaptivePresentationControllerDelegate
的新方法(从 iOS 8.3 开始)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
告诉呈现控制器使用原始呈现样式,在您的情况下将显示弹出窗口。