Swipe back and forward on navigationController

对着背影说爱祢 提交于 2019-12-21 02:59:25

问题


Each UIViewController, starting with rootViewController uses [self.navigationController pushViewController nextView] to push new views. Swipe works fine.

How can I implement the same behavior for the swipe forward? I more exactly, how I keep the UIViewController after popped with swipe back or back button, so I can add it again in case of swipe forward?


回答1:


To keep track of your view controllers, you could do the following:

  • Add an instance variable (as a strong property) nextViewController to all your view controllers

  • Whenever you push a new view controller, set nextViewController to the pushed view controller

  • Now, whenever the user swipes forward, you just push the nextViewController. But, first check for nil. If currentViewController.nextViewController = nil you know that the user has never navigated beyond this point, and you handle appropriately. You could just ignore the swipe forward, or you could send the user a message.

To handle the swipe itself:

  • Just add a UISwipeGestureRecognizer to each view controller's view.

  • Then, when your swipe method is called, check the gesture recognizer's direction property. If it was a forward swipe, push the nextViewController as described above.



来源:https://stackoverflow.com/questions/5891432/swipe-back-and-forward-on-navigationcontroller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!