jjzjj

ios - 为什么 presentationController 不是 :viewControllerForAdaptivePresentationStyle: being called?

coder 2023-09-26 原文

我正在尝试通过自适应弹出窗口以编程方式呈现 View (例如,在 iPad 上的弹出窗口中,在 iPhone 上全屏显示)。为了能够关闭 iPhone 上呈现的 View Controller ,我尝试将其包装在导航 Controller 中,如 https://stackoverflow.com/a/29956631/5061277 所示。或者这里的好例子:https://github.com/shinobicontrols/iOS8-day-by-day/tree/master/21-alerts-and-popovers/AppAlert ,看起来像:

import UIKit

class ViewController: UIViewController, UIPopoverPresentationControllerDelegate {

  @IBAction func handlePopoverPressed(sender: UIView) {
    let popoverVC = storyboard?.instantiateViewControllerWithIdentifier("codePopover") as! UIViewController
    popoverVC.modalPresentationStyle = .Popover
    // Present it before configuring it
    presentViewController(popoverVC, animated: true, completion: nil)
    // Now the popoverPresentationController has been created
    if let popoverController = popoverVC.popoverPresentationController {
      popoverController.sourceView = sender
      popoverController.sourceRect = sender.bounds
      popoverController.permittedArrowDirections = .Any
      popoverController.delegate = self
    }
  }

  func adaptivePresentationStyleForPresentationController(controller: UIPresentationController) -> UIModalPresentationStyle {
    // This line _IS_ reached in the debugger
    NSLog("Delagate asked for presentation style");
    return .FullScreen
  }

  func presentationController(controller: UIPresentationController, viewControllerForAdaptivePresentationStyle style: UIModalPresentationStyle) -> UIViewController? {

    // This line _IS_NOT_ reached in the debugger
    NSLog("Delegate asked for view controller");
    return UINavigationController(rootViewController: controller.presentedViewController)


  }
}

在调用 adaptivePresentationStyleForPresentationController 委托(delegate)方法时,不会调用 presentationController viewControllerForAdaptivePresentationStyle 委托(delegate)方法。因此,无法关闭 iPhone 上显示的 Controller 。

我已经在 iOS 8.1 到 8.4 上尝试过 XCode 6.4 和 7.0b2,无论是在模拟器上还是在设备上,在任何情况下我的代表都不会要求 viewControllerForAdaptivePresentationStyle。为什么?是否有我应该查看的build设置,或者安装 XCode 7 是否可以改变某些东西?这个确切的代码在上面的链接中显示为有效。

最佳答案

配置完成后需要呈现。或者使用 segue 使其更容易。

关于ios - 为什么 presentationController 不是 :viewControllerForAdaptivePresentationStyle: being called?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31224089/

有关ios - 为什么 presentationController 不是 :viewControllerForAdaptivePresentationStyle: being called?的更多相关文章

随机推荐