【发布时间】:2016-09-05 09:28:21
【问题描述】:
当我尝试从 UICollectionViewController 调用自定义 UIPresentationController 时,我的应用程序崩溃了
@IBAction func showSettingsMenu(sender: UIBarButtonItem) {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
if let mvc = storyboard.instantiateViewControllerWithIdentifier(Constants.SettingsViewControllerId) as? SettingsViewController {
mvc.modalPresentationStyle = .Custom
mvc.transitioningDelegate = self
presentViewController(mvc, animated: true, completion: nil)
}
}
这是我的自定义演示视图控制器:
class SpecialSizePresentationController: UIPresentationController {
override func frameOfPresentedViewInContainerView() -> CGRect {
guard let height = containerView?.bounds.height else {
return CGRectZero
}
guard let width = containerView?.bounds.width else {
return CGRectZero
}
let y = height * 0.6
let frameHeight = height * 0.4
return CGRectMake(8, y - 8 , width - 8 - 8 , frameHeight)
}
}
这是我的 UICollectionViewController 中的 UIViewControllerTransitioningDelegate 协议实现:
func presentationControllerForPresentedViewController(presented: UIViewController, presentingViewController presenting: UIViewController, sourceViewController source: UIViewController) -> UIPresentationController? {
return SpecialSizePresentationController(presentedViewController: presented, presentingViewController: presenting)
}
应用程序在返回位置崩溃并出现错误(由于呈现为零):
fatal error: unexpectedly found nil while unwrapping an Optional value
是否可以从 UICollectionViewController 呈现自定义 Presentation Controller?
如何实现?
【问题讨论】:
标签: swift presentviewcontroller