检测 UINavigationBar 中的滑动
我试图让我的视图控制器检测由我的应用程序自动显示的 UINavigationBar 中的滑动,但它拒绝检测滑动。我有什么办法可以做到吗?
I am trying to get my view controller to detect swipes in the UINavigationBar that is automatically displayed by my app, but it refuses to detect swipes. Is there any way I can do it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设您想检测导航栏中向左的滑动,您可以在创建导航控制器时执行以下操作:
然后创建一个如下所示的方法来处理它:
OBS:As您的导航控制器是一个将在应用程序生命周期的几个步骤中保持活动状态的类,请务必注意这一点,并仅在创建导航控制器时添加手势识别器(这意味着仅添加一次),以便您不要不断地堆积手势识别器,这不仅会导致内存泄漏,而且还可能使您的方法
didSwipedLeft
被多次调用。Supposing you want to detect swipes to the left in your navigation bar, you could do something like this when you create the navigation controller:
and then create a method like the one below to handle it:
OBS: As you navigation controller is a class that will remain alive for several steps of you application life cycle, it is important to pay attention to that and add the gesture recognizer only when you create the navigation controller (which means only add it once) so that you dont keep piling gestures recognizer one over each other, wich will lead not only to a memory leak, but also might make your method
didSwipedLeft
to be called more than once.