UIScrollView和Button中手势冲突

思路:在UIScrollView中设置手势监听。通过找到手势的位置确定是否点击了Button

1、为UIScrollView设置手势

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(bootButtonAction:)];
[pageScrollView addGestureRecognizer:tap];

2、对比点击的位置是否在Button范围内

-(void) bootButtonAction:(UIGestureRecognizer *) sender{
    //取得所点击的点的坐标
    CGPoint point = [sender locationInView:self];
    // 判断该点在不在区域内
    if (CGRectContainsPoint(button.frame, point))
    {
       //操作
        [self removeFromSuperview];
    }

}
原创文章 98 获赞 14 访问量 15万+

猜你喜欢

转载自blog.csdn.net/TaLinBoy/article/details/72287141