举个例子:首先,视图的层次关系是self.view - > viewA->buttonA - >ViewB
想触发被viewB覆盖的buttonA事件.
需要重写ViewA的两个方法:
1.- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
2.- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
代码如下:
viewA.h
<pre name="code" class="objc">#import <UIKit/UIKit.h>
@interface viewA : UIView
@property (nonatomic, strong) UIButton *btn;
@end
View.m
#import "viewA.h"
@implementation viewA
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
UIView *reView = [super hitTest:point withEvent:event];
CGPoint point1 = [_btn convertPoint:point1 toView:self];
if ([_btn hitTest:point1 withEvent:event]) {