iOS5 UITapRecognizer for UIScrollView interfering with buttons. How to fix?

后端 未结 3 443
我在风中等你
我在风中等你 2020-12-28 23:20

I have a bunch of UIButtons within a UIView within a UIScrollView. I\'m trying to add a tap recognizer to the scroll view. The tap rec

3条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-28 23:38

    For me a combo of the above answers worked

    UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(userDidTap:)];
    tapRecognizer.cancelsTouchesInView = YES;
    tapRecognizer.delegate = self;
    [tapRecognizer requireGestureRecognizersToFail:self.scrollView.gestureRecognizers];
    [self.view addGestureRecognizer:tapRecognizer];
    

    -

    - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
    {
        if ([touch.view.superview isKindOfClass:[UIButton class]] || [touch.view isKindOfClass:[UIButton class]])
        {
            return NO;
        }
        return YES;
    }
    

提交回复
热议问题