I had a custom view with subclassed touch responses that was working in iOS 4. On iOS 5, these touches would not respond at all when touched along the bottom edge of the view, if the view's background color was set to clearColor
.
I have not been able to track this down, but does anyone know if iOS 5 changed the way views respond to touches depending on a transparent background?
I can make no changes to the code other than set the background color to any opaque color like orangeColor
and the view fully responds.
Note the issue does not affect touches elsewhere in the view; only along the bottom edge, anywhere below the last subview added to the view; presumably a clear background is treated as if the view does not exist for the sake of touches when looking at an area of the view that has no content. Change the color, the view has "content" and the touches work!
Instead of using
[UIColor clearColor]
, try using this:NOTE: A
UIView
does not respond to touch events when thealpha
is anything below0.1
.[UIColor clearColor]
sets analpha
to0.0
, so you won't get the touch events. Following the above method, you can receive the touch events on a transparent view.In case anyone else runs into this problem and wants a better solution than setting a partial opacity for the background, you can set the view's
opaque
property toNO
and then add an emptydrawRect:
method. (Tested and working on iOS8, beta 4.)