在navigationController上向后和向前滑动 [英] Swipe back and forward on navigationController

查看:105
本文介绍了在navigationController上向后和向前滑动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每个UIViewController,以rootViewController开头,使用[self.navigationController pushViewController nextView]来推送新视图。滑动工作正常。

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

如何向前滑动实现相同的行为?更确切地说,我在弹出后退或后退按钮后如何保持UIViewController,所以我可以在向前滑动的情况下再次添加它?

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?

推荐答案

要跟踪视图控制器,您可以执行以下操作:

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


  • 向所有视图控制器添加一个实例变量(作为强属性) nextViewController

无论何时推送新的视图控制器,将 nextViewController 设置为推送的视图控制器

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

现在,每当用户向前滑动时,只需按 nextViewController 即可。但是,首先检查 nil 。如果 currentViewController.nextViewController = nil 您知道用户从未导航过这一点,并且您处理得当。您可以忽略向前滑动,或者您可以向用户发送消息。

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.

要处理滑动本身:


  • 只需将UISwipeGestureRecognizer添加到每个视图控制器的视图

然后,当您的滑动方法被调用时,请检查手势识别器的方向属性。如果是向前滑动,请按上述方法按 nextViewController

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.

这篇关于在navigationController上向后和向前滑动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆