Schoob
Schoob

Reputation: 1718

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.

Upvotes: 0

Views: 877

Answers (1)

dasdom
dasdom

Reputation: 14073

You could use touchesBegan:withEvent.

Upvotes: 1

Related Questions