检测 UIBarButtonItem 中的触摸或按下
我有一个显示照片的 ScrollView。当触摸屏幕时,会弹出一个 UIToolBar,其中有几个 UIBarButtonItem 按钮,如上一个、下一个、播放……如果用户 5 秒内没有执行任何操作,工具栏会再次消失。
这与 Apple Photos 应用程序非常相似。
一切都按预期工作,但有一件事我正在努力解决:如果用户按下按钮,我无法获得触摸,也无法检查按钮的突出显示状态。
因此,如果用户按住按钮几秒钟,就会出现问题……程序会假设什么都没有发生,并在 5 秒过去后删除工具栏。
照片应用程序不存在此问题。更好的是:当您按住“下一个”或“上一个”按钮或按住超过一秒时,它已经执行与 UIBarButtonItem 关联的“操作”!
简而言之,我想做其中之一: - 了解 UIBarButtonItem 是否被按下 - 了解 UIBarButtonItem 是否突出显示 - 或者只是知道是否有任何媒体报道
I have a ScrollView which shows photos. When touching the screen, a UIToolBar pops up, with several UIBarButtonItem buttons, like Previous, Next, Play... If the users doesn't do anything for 5 seconds, the toolbar disappears again.
It's all very similar to the Apple Photos app.
Everything works as it should, but there's one thing I'm struggling with: I cannot get touches for if the user pressed the buttons, nor can I check on the highlight status of the button.
So there's a problem if the user keeps a button pressed for a few seconds... the program will assume nothing has happened, and remove the toolbar after the 5 seconds have passed.
The Photos app does not have this problem. Even better: when you keep the Next or Previous button pressed or longer than a second, it already executes the "action" associated with the UIBarButtonItem !
In short, I want to do one of these:
- to know whether a UIBarButtonItem is pressed
- to know whether a UIBarButtonItem is highlighted
- or else just know whether there's any press anywhere going on
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试附加
UIGestureRecognizer
的自定义子类,它会告诉您用户何时与工具栏的视图交互。或者,您可以尝试子类化
UIToolbar
并更改其-[touchesBegan:withEvent:]
和-[touchesEnded:withEvent:]
方法来告诉您当用户开始/停止与工具栏上的任何内容交互时。后者可能更简单。
You could try attaching a custom subclass of
UIGestureRecognizer
, which tells you when the users interacts with the view to the toolbar.Alternatively, you could try subclassing
UIToolbar
and change its-[touchesBegan:withEvent:]
and-[touchesEnded:withEvent:]
methods to tell you when the users starts/stops interacting with anything on the toolbar.The latter is probably simpler.