在 navigationController 上前后滑动
每个 UIViewController,从 rootViewController 开始,使用 [self.navigationController PushViewController nextView] 来推送新视图。滑动效果很好。
如何为向前滑动实现相同的行为?更准确地说,如何在使用向后滑动或后退按钮弹出后保留 UIViewController,以便在向前滑动时可以再次添加它?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要跟踪您的视图控制器,您可以执行以下操作:
向所有视图控制器添加一个实例变量(作为强属性)
nextViewController
nextViewController
设置为推送的视图控制器现在,每当用户向前滑动时,您只需推送
nextViewController
即可。但是,首先检查nil
。如果currentViewController.nextViewController = nil
您知道用户从未导航到超出此点,并且您可以进行适当的处理。您可以忽略向前滑动,也可以向用户发送一条消息。要处理滑动本身:
只需将 UISwipeGestureRecognizer 添加到每个视图控制器的
view
即可。然后,当调用您的滑动方法时,检查手势识别器的
direction
属性。如果是向前滑动,请如上所述推动nextViewController
。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 controllersWhenever you push a new view controller, set
nextViewController
to the pushed view controllerNow, whenever the user swipes forward, you just push the
nextViewController
. But, first check fornil
. IfcurrentViewController.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 thenextViewController
as described above.