Tyler Tyler - 1 year ago 140
Swift Question

UIView alpha 0 but still receive touch events?

I am trying to hide a uiview but still have it receive touch events. I am setting the alpha to 0 like so:

mainView.alpha = 0.0

also I've tried setting this to true but it doesn't do anything

mainView.userInteractionEnabled = true

Trouble is it no longer receives touch events when I do this. How can I enable it to receive touch events but be effectively hidden?

Answer Source

Set your UIView's backgroundColor to clearColor.

mainView.backgroundColor = UIColor.clearColor()
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download