iosswiftuimodaltransitionstyle

Is there any way to assign no UIModalTransitionStyle?


I know there are four types of UIModalTransitionStyles, but I would like not to use any of them.

However, this code doesn't work:

@IBAction func button(sender: AnyObject) {

    let modalView = ViewController()

    let storyboard = UIStoryboard(name: "Universal", bundle: nil)
    let vc = storyboard.instantiateViewControllerWithIdentifier("ViewController") as UIViewController
    modalView.modalTransitionStyle = nil // Error: type 'UIModalTransitionStyle' does not conform to protocol 'NilLiteralConvertible'

    self.presentViewController(vc, animated: true, completion: nil)

}

Whenever I don't specify the modalTransitionStyle, the compiler will get the modalTransitionStyle from the Storyboard document of UIViewController.

How can I set no modalTransitionStyle?


Solution

  • If you do not want a transition you should set the animated property to false when you present your new view controller.

    self.presentViewController(vc, animated: false, completion: nil)