开发者

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

开发者 https://www.devze.com 2022-12-19 04:45 出处:网络
Is there some optimization going on that removes the view or something? I still want it to recieve touch even开发者_Go百科ts even though I\'ve made it transparent. Seems these events don\'t fire if al

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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号