简体   繁体   中英

UIButton touch up inside event, bounds change?

So, I discovered an interesting behavior of UIButton after wasting a couple of hours late last night. I probably have come across this in the past but can't recall. I couldn't find an explanation for this behavior thus far, so please enlighten me if you have any info on this:

Create an instance of UIButton , then set its action for UIControlEventTouchUpInside . Now, in your running app, press on the button and hold down, move away from the button and notice how it seems like the bounds changed when moving/dragging your finger. The touch is recognized quite some distance from the button's original frame, bounds.

This caused quite some problems in my app where I implemented code using locationInView: to determine the indexPath of the UITableViewCell that is the superview of the button.

My two alternative solutions for determining the indexPath are:

  1. Use the buttons superview's superview, which is the UITableViewCell , together with UITableView's indexPathForCell : method.

  2. Rather use UIControlEventTouchDown when specifying my button action.

Hope someone finds this helpful or can contribute to a solution for the problem.

You could use touchesBegan:withEvent.

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