Home > Mobile >  How to go to the next view controller sliding by tapping on a button?
How to go to the next view controller sliding by tapping on a button?

Time:12-23

In the IBAction func what are the best code lines to write for showing a slide to next page after tapping on a button.

CodePudding user response:

How a UIViewController is presented (and animated) depends on the method you use to go to this new VC. It also depends on whether you're using a UINavigationController or not, for example. Lastly, you can modify how another VC is presented by changing the modalPresentationStyle of a VC (docs).

According to the UIViewController's present method documentation:

In a horizontally regular environment, the view controller is presented in the style specified by the modalPresentationStyle property. In a horizontally compact environment, the view controller is presented full screen by default. If you associate an adaptive delegate with the presentation controller associated with the object in viewControllerToPresent, you can modify the presentation style dynamically.

When using a UINavigationController, the pushViewController method will have this "sliding" animation (docs). This GitHub page might have some visual information to help you understand the differences.

CodePudding user response:

@IBAction func nextpage(_ sender: Any) {

let controller = storyboard?.instantiateViewController(withIdentifier: "StoryboardID") as! yourClassName

}
  • Related