UITabBarController - 模拟 UITabBarItem 上的双击
我有一个 UITabBarController
,如果我从第一个 UITabBarItem
推送到不同的视图,并且点击第一个 UITabBar
两次,则推送的视图被弹出。
我如何以编程方式模拟这个确切的功能?
I have a UITabBarController
, if I push to different views from the first UITabBarItem
and I tap the first UITabBar
two times then the views that were pushed are popped back.
How can I simulate this exact functionality programatically?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以实现
UITabBarController
的tabBarController:didSelectViewController:
方法来执行此操作。您可以在AppDelegate
中手动统计UITabBar
上的点击次数,并在方法中设置一定的条件。例如,您可以尝试在 .h 文件中包含一个实例变量,该变量存储最后选择的
UIViewController
以及选择的时间。如果您随后检查上次在同一方法中调用UIViewController
的时间,并且时间足够短,那么它将算作双击。希望有帮助!
You could implement the
tabBarController:didSelectViewController:
method of yourUITabBarController
to do this. You can manually count the number of taps on yourUITabBar
in theAppDelegate
, and have certain conditions in the method.For example, you could try in the .h file having an instance variable which stores the last
UIViewController
selected, and the time it was selected. If you then check the last time theUIViewController
was called in same method, and it was a short enough period, then it would count as a double tap.Hope that Helps!