The title of this post may sound like the start of a love song, but on a recent iPhone App project, I had a bit of trouble discovering why I could see my UIButton object, but couldn’t touch it. Specifically, it wouldn’t respond to touches!
What I found was worthy of short post, especially since I hadn’t found any solutions on Crack Overflow. Here is the Cocoa form I had lovingly co-created, and the big red button at the bottom was refusing to respond to touches.
What we have here is a UIView inside of a UIScrollView. The height of the UIView was about 30 pixels greater than the height of its parent UIScrollView. Also, when the UITextView gets the focus, I dynamically change the UIScrollView’s contentSize parameter to allow it to move into view smoothly (IMHO, it’s a lot of work to make a Cocoa form “work like it outghta” on the iPhone).
So after fiddling around with the heights of the form’s parent UIView, the UIView’s parent UIScrollView, the UIScrollView contentSize and a few juju charms, I decided to cast some light on the situation by setting the UIView’s background color to yellow.
This is what I found!
Just what I had suspected, the button was somehow outside of its parent UIView. But interestingly, it was still visible!
Don’t ask me why. Surely clipping it would give me some fast feedback as to the problem. However, when embedded in a UIScrollView, it doesn’t get clipped visually, but the touchable area is just as you set it.
After fixing the height of the form’s parent UIView, this is what I had, and it worked.
Peace at last.



[...] This post was mentioned on Twitter by Crunchy T, Long Weekend. Long Weekend said: I can see you, but I can't touch you! When UIButtons stop responding to touches inside UIScrollViews. Our solution … http://ow.ly/2OrZs [...]
Tweets that mention I Can See You, But I Can’t Touch You – iPhone UIView Touchability | Long Weekend - iPhone & iPad Apps You'll Love! -- Topsy.com
October 5th, 2010
Big Bucket – Archive – Retro 8-Bit Retina Display Support…
I found your entry interesting thus I’ve added a Trackback to it on my weblog
…
The BB and Iphone Zone
October 27th, 2010
Hi,
this is a VERY helpful post. I was poking around for hours trying to find why my App wasn’t doing what it was supposed to do. Needless to say that I fell into above described trap. After increasing the height of my UIView everything worked fine.
I mentioned your post in the Apple iPhone Developers Forum.
Thanks
Mat
Mat
April 28th, 2011