在 navigationController 上前后滑动

发布于 2024-11-05 10:28:57 字数 207 浏览 0 评论 0原文

每个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

丘比特射中我 2024-11-12 10:28:57

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

  • 向所有视图控制器添加一个实例变量(作为强属性)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 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文