我有一个和屏幕一样大的view,上面有一个很小的button
然后我修改了View的
-(UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
return btn;
}
然后我发现,button被点击的范围确实增大了。。。但是只增大了大概一倍,并不能和整个view一样,代码如下
viewcontroller里面
View *view = [[View alloc]initWithFrame:self.view.bounds];
[self.view addSubview:view];
view里面
@implementation View
{
Button * btn;
}
-(instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
btn = [[Button alloc]initWithFrame:CGRectMake(100, 100, 200, 30)];
[btn setTitle:@"1" forState:UIControlStateNormal];
btn.backgroundColor = [UIColor blueColor];
[self addSubview:btn];
btn.tag = 1;
[btn addTarget:self action:@selector(miao:) forControlEvents:UIControlEventTouchUpInside];
}
return self;
}
-(void)miao:(UIButton *)button
{
NSLog(@"%@",@(button.tag));
}
-(UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
NSLog(@"%@",NSStringFromCGPoint(point));
return btn;
}