3

我想始终在所有设备和所有方向的弹出窗口中显示一个视图控制器。我试图通过采用UIPopoverPresentationControllerDelegateand 设置sourceViewand来实现这一点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
}
4

1 回答 1

7

实现新的(从 iOS 8.3 开始)adaptivePresentationStyleForPresentationController:traitCollection:方法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告诉演示控制器使用原始演示样式,在您的情况下将显示一个弹出框。

于 2015-05-27T13:35:19.343 回答