3

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?

Cesare
  • 9,139
  • 16
  • 78
  • 130
  • How are you presenting this `modalView`? can you show more code please? – Wez Feb 20 '15 at 09:44
  • possible duplicate of [PresentViewController with custom “scale-from-center” ModalTransitionStyle](http://stackoverflow.com/questions/15809727/presentviewcontroller-with-custom-scale-from-center-modaltransitionstyle) – Lord Zsolt Feb 20 '15 at 09:47
  • @Wezly I added more code. – Cesare Feb 20 '15 at 09:50
  • @LordZsolt Thanks for your input. It is not a duplicate since this answers are written in Objective-C. – Cesare Feb 20 '15 at 09:52
  • I think it's worth pointing out that in your code the `modalView` is not even being used, the `vc` you are presenting is displayed from the storyboard. – Wez Feb 20 '15 at 10:00
  • Well translating the code from Obj-C to Swift shouldn't be a challenge... – Lord Zsolt Feb 20 '15 at 10:54

1 Answers1

7

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)
Wez
  • 10,555
  • 5
  • 49
  • 63