为什么不是presentationController:viewControllerForAdaptivePresentationStyle:被调用?

Chr*_*and 5 iphone ios

我正在尝试通过自适应弹出窗口以编程方式呈现视图(例如,在iPad上的popover,iPhone上的全屏).为了能够解除iPhone上呈现的视图控制器,我尝试将其包装在导航控制器中,如/sf/answers/2096964201/或这里的好例子: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)


  }
}
Run Code Online (Sandbox Code Playgroud)

调用adaptivePresentationStyleForPresentationController委托方法时,不调用presentationController viewControllerForAdaptivePresentationStyle委托方法.因此,无法解除iPhone上呈现的控制器.

我已经在iOS 8.1到8.4上尝试过XCode 6.4和7.0b2,无论是在模拟器中还是在设备上,在任何情况下我的委托都不会要求viewControllerForAdaptivePresentationStyle.为什么?是否有我应该看的构建设置,或者安装XCode 7是否会改变某些东西?此精确代码显示为在上面的链接中工作.

wj2*_*061 0

你需要添加这个方法:

-(UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller traitCollection:(UITraitCollection *)traitCollection{
    return UIModalPresentationOverFullScreen;
}
Run Code Online (Sandbox Code Playgroud)