UIButton touch up inside event not working in ios5 while it's ok in ios6

99封情书 提交于 2019-12-03 14:00:05

I had the same problem to you. That's because the touch event in iOS5 is prevented when the gestureRecognizer you registered captures the event.

There are two solutions.

One:

1) Add a new view inside your view. It should have the same level to the buttons. The priority of the buttons should be higher than the new view.

2) change the call of 'addGestureRecognizer' to the new view.

[self.newView addGestureRecognizer:tap];

Two:

1) Implement the code below. You should return NO when the point is in the buttons.

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
    CGPoint point = [gestureRecognizer locationInView:self.view];

    NSLog(@"x = %.0f, y = %.0f", point.x, point.y);
    if (CGRectContainsPoint(self.testBtn.layer.frame, point))
        return NO;

    return YES;
}

ps. you should import QuartzCore.h to access layer's attributes.

#import <QuartzCore/QuartzCore.h>

Just use the property "cancelsTouchesInView" (NO) on UITapGestureRecognizer tap

Example:

UITapGestureRecognizer *gesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didTap)];
gesture.cancelsTouchesInView = NO;
[self.view addGestureRecognizer:gesture];

Override your button parent view pointinside method, setting a new custom frame size that contains your button.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!