如何在modaly swift 4中呈现ViewController

时间:2017-12-22 04:59:30

标签: ios xcode uiviewcontroller swift4

我如何在模态中呈现viewController。我是ios的新手,我正在使用swift4 我试试这个

 let userVC = mainStoryboard.instantiateViewController(withIdentifier: 
  "menuC") as! MenuController
    userVC.modalPresentationStyle = UIModalPresentationStyle.overCurrentContext
      userVC.navigationController?.modalPresentationStyle = 
    UIModalPresentationStyle.overCurrentContext
    present(userVC, animated: true, completion: nil)

1 个答案:

答案 0 :(得分:5)

这样做

if let presentedViewController = self.storyboard?.instantiateViewController(withIdentifier: "menuC") {
        presentedViewController.providesPresentationContextTransitionStyle = true
        presentedViewController.definesPresentationContext = true
        presentedViewController.modalPresentationStyle = UIModalPresentationStyle.overCurrentContext;
        presentedViewController.view.backgroundColor = UIColor.init(white: 0.4, alpha: 0.8)
        self.present(presentedViewController, animated: true, completion: nil)
    }