修改hitTestView 遇到了问题

我有一个和屏幕一样大的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;
}
阅读 1.6k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进