首先我们要了解 iOS 是通过 hit-testing 这个玩意找到用户点击了哪个位置。
hit-testing
hit-testing 会判断是否在父视图范围内,否则返回nil 自然我们也就无法实现点击了。
我们必须重写- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)eventt方法
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)eventt
在父视图中加入下面方法即可实现点击事件。