@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)
}
并且app在错误的返回位置崩溃(由于呈现为零):
fatal error: unexpectedly found nil while unwrapping an Optional value
是否可以从UICollectionViewController呈现自定义Presentation Controller?
如何实施?
答案 0 :(得分:0)
我使用source
presenting
的{{1}}问题解决了这个问题,错误消失了