在iOS6中处理手势识别器 [英] Handling gesture recognizers in iOS6

查看:93
本文介绍了在iOS6中处理手势识别器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

显然,当你在同一个地方有一个手势识别器和一个 UIButton 时,iOS 6会尝试自动处理这种情况,并为同一个手势激活。

Apparently iOS 6 tries to automatically handle the situation when you have a gesture recognizer and a UIButton in the same place, being activated for the same gesture.

当你想要点击按钮而不是激活手势识别器时,这个新的自动处理解决了这个问题,但当你想要手势识别器时会产生新的问题行动。

This new automatic handling solves the issue when you want to click the button instead of activating the gesture recognizer, but creates a new problem when you want the gesture recognizer to act.

在iOS 5中你可以实现:

In iOS 5 you could implement:

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch

转移动作冲突时到 UIButton

这在iOS 6中似乎不起作用。另外,反转此方法的行为(因为现在 UIButton 具有优先权而不是手势识别器)将无法工作。

This doesn't seem to work in iOS 6. Also, inverting the behavior of this method (because now the UIButton has the priority instead of the gesture recognizer) won't work.

完整方法:

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


推荐答案

我这样做是为了解决问题,根据需要更改它:

I've done this to workaround the issue, change it as you see fit:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
      [self MyCommonSelector];// this will work for ios 5
      return Yes;
 }

在你声明的按钮中添加目标,这将在iOS 6中调用:

Add target in button where you declare so this will call in iOS 6:

[self.myButton addTarget:self action:@selector(MyCommonSelector)
  forControlEvents:UIControlEventTouchUpInside];

用这个方法做你的东西,也可以通过按钮点击并从你需要的手势调用致电:

Do your stuff in this method which will also be called on button tap and from the gesture you need to call:

-(void)MyCommonSelector
 {
    //Do your stuff here what you want to do with Gesture too.
 }

这篇关于在iOS6中处理手势识别器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆