How do you recognize drag gestures

我是研究僧i 提交于 2019-12-08 03:54:31

问题


I have several buttons in my view built using IB. Each button triggers a short audio sound.

I want to be able to drag my finger over them to trigger them... just like you are dragging your finger over piano keys (don't worry I am not making a piano app)

I cant figure out how to recognize a touch outside the button and then inside it.

Any ideas?

Thanks


回答1:


As your buttons subclass from UIControl, you can use UIControl's implementation of recognition of gestures.

Look at UIControl's - (void)addTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents. This will let you specify a method on an object to be called whenever certain events occur. The possible events are, among others:

   UIControlEventTouchDragInside     = 1 <<  2,
   UIControlEventTouchDragOutside    = 1 <<  3,
   UIControlEventTouchDragEnter      = 1 <<  4,

A complete list is available in Apple's documentation for Control Events.

When UIControlEventDragOutside fires, you may want to reevaluate which view is currently playing.



来源:https://stackoverflow.com/questions/1345154/how-do-you-recognize-drag-gestures

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!