如何检测进入 UIButton 框架的触摸?
我正在编写一个实现钢琴键盘的类。现在它只是一个 UIView,每个键都是一个 UIButton。我希望用户能够拖动手指并敲击几个键,但现在它只记录触地。我添加了 UIControlEventTouchDragEnter 作为触发按键事件的一种方式,但只有当您按下一个键,将手指拖动到其他位置,然后将其拖回同一键时,它才有效。
有没有办法检测 UIButton 的拖动事件?我是否必须重新开始并为每个键使用其他东西?我不想根据坐标来计算触摸是哪个键,因为这似乎是不必要的。您认为做到这一点最简单的方法是什么?
谢谢,
卢克
I'm writing a class that implements a piano keyboard. Right now it's just a UIView and each key is a UIButton. I'd like the user to be able to drag their finger and hit several keys, but right now it only registers touch down. I've added UIControlEventTouchDragEnter as a way to trigger the key event but it only works if you hit a key, drag your finger elsewhere, and drag it back to the same key.
Is there a way to detect drag events with UIButtons? Will I have to start over and use something else for each key? I don't want to calculate which key the touch is on based on its coordinates because that seems like it should be unnecessary. What do you think is the simplest way to do this?
Thanks,
Luke
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以跟踪 UIControlEventTouchUpOutside 最后按下的按钮,及其处理程序检查,用户将手指移动到哪个按钮。
You can track UIControlEventTouchUpOutside for the last pressed button, and it's handler check, to which button user moved his/her finger.