iPhone 6 Plus 的 UIModalPresentationPopover 横向不显示弹出窗口
UIModalPresentationPopover for iPhone 6 Plus in landscape doesn't display popover
我想始终在所有设备和所有方向上的弹出窗口中显示 ViewController
。我试图通过采用 UIPopoverPresentationControllerDelegate
并设置 sourceView
和 sourceRect
来实现这一点。
这适用于所有设备和方向,但 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 }
所有设备都在 iOS 8.2 或更高版本
Apple 根据 class 的尺寸 class.
设计了 iPhone 6 Plus 演示文稿以实现这种行为
要防止 iPhone 6 Plus 上的模态显示,您必须覆盖特征集合(水平尺寸)。
您应该能够为演示控制器设置 overrideTraitCollection
属性:
presentedVC.presentationController.overrideTraitCollection = [UITraitCollection traitCollectionWithHorizontalSizeClass:UIUserInterfaceSizeClassCompact];
(对不起Objective C!我还没有学会Swift。)
实施 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
告诉呈现控制器使用原始呈现样式,在您的情况下将显示弹出窗口。
在 Swift 3 中,如果您实现了原始的 adaptivePresentationStyle
方法,只需添加以下代码即可:
func adaptivePresentationStyle(for controller: UIPresentationController, traitCollection: UITraitCollection) -> UIModalPresentationStyle {
return adaptivePresentationStyle(for: controller)
}
给遇到此问题的人的注意事项:
这个
- (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *) controller traitCollection:(UITraitCollection *)traitCollection {
return UIModalPresentationNone;
}
和这个不一样
- (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController: (UIPresentationController * ) controller {
return UIModalPresentationNone;
}
后者不会像前者一样被调用/工作。
我想始终在所有设备和所有方向上的弹出窗口中显示 ViewController
。我试图通过采用 UIPopoverPresentationControllerDelegate
并设置 sourceView
和 sourceRect
来实现这一点。
这适用于所有设备和方向,但 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 }
所有设备都在 iOS 8.2 或更高版本
Apple 根据 class 的尺寸 class.
设计了 iPhone 6 Plus 演示文稿以实现这种行为要防止 iPhone 6 Plus 上的模态显示,您必须覆盖特征集合(水平尺寸)。
您应该能够为演示控制器设置 overrideTraitCollection
属性:
presentedVC.presentationController.overrideTraitCollection = [UITraitCollection traitCollectionWithHorizontalSizeClass:UIUserInterfaceSizeClassCompact];
(对不起Objective C!我还没有学会Swift。)
实施 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
告诉呈现控制器使用原始呈现样式,在您的情况下将显示弹出窗口。
在 Swift 3 中,如果您实现了原始的 adaptivePresentationStyle
方法,只需添加以下代码即可:
func adaptivePresentationStyle(for controller: UIPresentationController, traitCollection: UITraitCollection) -> UIModalPresentationStyle {
return adaptivePresentationStyle(for: controller)
}
给遇到此问题的人的注意事项:
这个
- (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *) controller traitCollection:(UITraitCollection *)traitCollection {
return UIModalPresentationNone;
}
和这个不一样
- (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController: (UIPresentationController * ) controller {
return UIModalPresentationNone;
}
后者不会像前者一样被调用/工作。