简体   繁体   中英

How to make a switch from one view to the same view?

I'm creating a questionnaire app for iOS in Swift. I only need one view for all questions. How do I make one generic view and make it look like I'm switching to the new view with swipe when only replacing some of the data on that view?

You can add an animation to your subviews (UILabels, etc.) on screen. You can add a separate animation to each swipe gesture and have the animation move in the direction of the swipe. I like this because you have some flexibility in what you animate and how you do so.

You'll need to setup swipe gesture recognizers and methods for each to handle the swipe and animate the layers.

If you want a "traditional feeling" swipe left / swipe right type of setup you'll need to setup a push animation with a subtype for each direction.

Alright, so I think I know what you're attempting to do. You could possibly do it like this. This is assuming you have a custom UIViewController subclass with all your textfields and labels on it; I've named this QuestionaireViewController .

let nextVC = QuestionaireViewController()
self.navigationController?.pushViewController(nextVC, animated: true)

Additionally, you'll want to set up unwind segues each time you create a new VC, so that if needed the Navigation Controller can segue back.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM