Slide to and from UIButtons and make them respond

血红的双手。 提交于 2019-12-25 01:07:33

问题


I am creating a semi-piano app in Objective-C for iPhone; it's in fact a diffrent layout MIDI Controller, but I'm still working on the design.

I created all of the "keys" with UIButtons, and I want to be able to slide to them or from them to other UIButtons.

I read all the similar questions before, but I couldn't make it to work with touchesMoved, Because it only worked from the view if I didn't drag the finger from a UIButton.

Thanks in advance, code will be appreciated!


回答1:


Are your buttons created in IB? The default event when connecting buttons in IB is "touch up inside", which means the action is fired when the user ends a touch (lifts the finger) inside the button. A piano key or similar would be more appropriate to fire on the "touch down inside" (for the initial press) and the "touch drag enter" (for when a finger that is already on the screen moves into the button).

Since you are doing it programmatically, you can add targets to the buttons as described here:

http://developer.apple.com/library/ios/documentation/uikit/reference/UIControl_Class/Reference/Reference.html#//apple_ref/occ/instm/UIControl/addTarget:action:forControlEvents:

Just include the events you want in the mask.



来源:https://stackoverflow.com/questions/8195420/slide-to-and-from-uibuttons-and-make-them-respond

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