按住 iPhone 按钮 3 秒会转到不同的视图
我的应用程序中有一个按钮,按下该按钮会转到视图 但我需要,当按下 3 秒时,它会进入不同的视图,
就像当你在 Safari 上的 ipad 上时,按住 url,它会显示一个带有副本等的弹出窗口,
但当按下 3 秒时,我需要它其次它转向另一种观点......
希望这是有道理的,如果不理解我会更好地解释,
非常感谢! pd,还如何让它显示弹出式窗口? 干杯!
I have a button in my app that when pressed goes to a view
but I need that when pressed for 3 seconds it would go to a different view,
like when you are on ipad on safari and you keep pressed the url, and it shows a pop up with copy etc,
but I need that when pressed for 3 second it goes to another view...
hope this makes sense, I will explain better if not understood,
thank you so much!
pd, also how to make it show the pop up style window?
cheers!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试在视图控制器中设置
NSTimer
属性。按下按钮后,创建计时器并将其分配给您的属性。您可以使用以下命令检测该时刻:并使用以下命令进行分配:
然后设置一个操作在取消的触摸或内部触摸上运行:
这
应该可以解决它!
Try setting an
NSTimer
property in your view controller. When the button's pressed, create the timer and assign it to your property. You can detect that moment with this:and assign with this:
Then set an action to run on a canceled touch, or a touch up inside:
and
That should take care of it!
使用
UILongPressGestureRecognizer
,通过-addGestureRecognizer:
添加到按钮 - 它将处理触摸计时并在识别到按钮已被按住一段时间时触发事件。不过,您可能需要重新考虑您的交互模式,通常,可以长按的不是按钮,它们是视图中的实际数据片段,例如 Safari 中的图像或链接。Use a
UILongPressGestureRecognizer
, added to the button with-addGestureRecognizer:
—it'll handle timing the touch and fire an event when it recognizes that the button's been held down for a while. You might want to reconsider your interaction pattern, though—generally, things that can be long-pressed aren't buttons, they're actual pieces of data in a view, like an image or a link in Safari.一种可能的方法是实现一个触摸事件(我不记得名称,但是当您按下按钮时触发的方法),并安排一个计时器在三秒内触发。如果用户在此时间之前抬起手指,则取消计时器并执行正常的按钮单击。如果时间确实触发(即 3 秒过去),请忽略触摸事件并加载新视图。
One possible approach would be to implement one of the touches events (I don't remember the name, but the method that fires when you touch down on the button), and schedule a timer to fire in three seconds. If the user lifts her finger before that time, cancel the timer and perform the normal button click. If the time does fire (i.e. 3 seconds have elapsed), ignore the touch up event and load your new view.