2016-09-05 63 views
0

我的应用程序崩溃时,我尝试从UICollectionViewController调用自定义UIPresentationController应用程序崩溃的原因UICollectionViewController不能presentingViewController

@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定制的控制人?

它是如何实现的?

回答

0

我解决了这个问题,使用source insth的presenting和错误消失了

相关问题