UIView alpha 0 but still receive touch events?
Set your UIView
's backgroundColor
to UIColor.clear
.
mainView.backgroundColor = .clear
There are two ways to handle this:
The hard one - instead of setting alpha on the view, set it on all its subviews and make all the content in the view invisible (e.g. change background to clear color).
The easy one - let another view handle the events. Just add another transparent view with the same position and size (which is easy using constraints) which will handle the events.
By the way, if you check the documentation for method hitTest:withEvent: which is used to handle touch events, it says that views with alpha
lower than 0.01
won't receive touches.
Hide all subviews of the view and set the backgroundColor to UIColor clearColor