morgancodes
morgancodes

Reputation: 25265

iPhone -- Why doesn't touchesBegan fire on UIViews when alpha is set to zero?

Is there some optimization going on that removes the view or something? I still want it to recieve touch events even though I've made it transparent. Seems these events don't fire if alpha == 0 though.

Upvotes: 4

Views: 3391

Answers (1)

Andrew Johnson
Andrew Johnson

Reputation: 13286

You're right, touches don't get detected on transparent views:

"By default, a view receives touch events, but you can set its userInteractionEnabled property to NO to turn off delivery of events. A view also does not receive events if it’s hidden or if it’s transparent."

How about setting the view to 1% alpha, or even a few points? Maybe your UI should show a ghost overlay anyways.

The other thing you could do is make a UIView subclass, frame it to the same size, and overlay it. A UIView has a background color of [UIColor clearColor] by default, but you can still detect touches on it.

Upvotes: 4

Related Questions