如何检测进入 UIButton 框架的触摸?

发布于 2024-09-15 11:58:39 字数 291 浏览 1 评论 0原文

我正在编写一个实现钢琴键盘的类。现在它只是一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

別甾虛僞 2024-09-22 11:58:39

您可以跟踪 UIControlEventTouchUpOutside 最后按下的按钮,及其处理程序检查,用户将手指移动到哪个按钮。

You can track UIControlEventTouchUpOutside for the last pressed button, and it's handler check, to which button user moved his/her finger.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文