在横向上为iPhone 6 Plus设置UIModalPresentationStyle?

时间:2015-04-26 22:37:00

标签: ios uipresentationcontroller

我希望始终在所有设备和所有方向的弹出框中显示视图控制器。我尝试通过UIPopoverPresentationControllerDelegate并设置sourceViewsourceRect来实现这一目标。故事板中的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
}

1 个答案:

答案 0 :(得分:7)

实施adaptivePresentationStyleForPresentationController:traitCollection:的新{(iOS 8.3)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告诉演示控制器使用原始演示文稿样式,在您的情况下将显示弹出窗口。