gpt4 book ai didi

ios - 在 iOS6 中处理手势识别器

转载 作者:技术小花猫 更新时间:2023-10-29 10:17:33 25 4
gpt4 key购买 nike

显然,iOS 6 会尝试自动处理当手势识别器和 UIButton 在同一位置并为同一手势激活时的情况。

当您想单击按钮而不是激活手势识别器时,这种新的自动处理解决了问题,但当您希望手势识别器起作用时产生了一个新问题

在 iOS 5 中你可以实现:

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

在发生冲突时将操作转移到 UIButton

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


完整方法:

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

最佳答案

我这样做是为了解决这个问题,您可以根据需要进行更改:

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

在您声明的按钮中添加目标,以便在 iOS 6 中调用:

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

在这个方法中做你的事情,它也会在按钮点击和你需要调用的手势中被调用:

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

关于ios - 在 iOS6 中处理手势识别器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12518328/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com