滑动到 UIButtons 或从 UIButtons 滑出并使它们做出响应
我正在用 Objective-C 为 iPhone 创建一个半钢琴应用程序;它实际上是一个不同布局的 MIDI 控制器,但我仍在设计中。
我用 UIButtons 创建了所有“键”,并且我希望能够滑动到它们或从它们滑动到其他 UIButtons。
我之前读过所有类似的问题,但我无法使其与touchesMoved一起使用, 因为如果我没有从 UIButton 上拖动手指,它只能在视图中工作。
预先感谢,代码将不胜感激!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的按钮是在IB中创建的吗?在 IB 中连接按钮时的默认事件是“touch up inside”,这意味着当用户结束按钮内部的触摸(抬起手指)时会触发该操作。钢琴键或类似键更适合在“触摸内部”(对于初始按下)和“触摸拖动输入”(对于已经在屏幕上的手指移入按钮时)触发。
由于您是以编程方式执行此操作,因此您可以将目标添加到按钮,如下所述:
http://developer.apple.com/library/ios/documentation/uikit/reference/UIControl_Class/Reference/Reference.html#//apple_ref/occ/instm/UIControl/addTarget:action:forControlEvents< /a>:
只需在掩码中包含您想要的事件。
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.