简体   繁体   中英

How can I detect a touch entering the frame of a 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

您可以跟踪最后按下按钮的UIControlEventTouchUpOutside,以及它的处理程序检查,用户移动他/她的手指。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM