After the EDIT section:
https://github.com/soxjke/TransparentControl
1) If I set the background color +[UIColor clearColor] , then the touch will work just fine. Therefore, you do not need to do anything else, go ahead with a clear color. (top button)
2) If I set alpha = 0, touches are not processed. OK (middle button)
3) To handle this touch, there is a simple solution (bottom button), a subclass of UIButton (in fact, you can go with anything in the hierarchy to UIView ). Override hitTest:withEvent:
- (UIView*)hitTest:(CGPoint)point withEvent:(UIEvent *)event { return CGRectContainsPoint(self.bounds, point) ? self : nil; }
PROFIT
4) If you need to go deeper, use
touchesBegan:withEvent: touchesMoved:withEvent: touchesEnded:withEvent: touchesCancelled:withEvent:
in a subclass of UIResponder , such as Rob Glassey , proposed in it.
PS I would finish the topic. I donโt know what your task really is, but saying that you cannot use recognizers because you need to โhave more controlโ on all touch events, discovering that you do not know the capabilities of gesture recognizers. So, judging from my experience, I would say that you rather invent a bicycle, and then make a good decision.
PPS If other guys suggested me, the methods will not work here - check your control userInteractionEnabled
Application (view controller code to check :):
source share