提前致谢,我想分享UILongPressGestureRecognizer
.
UIView *v = [UIView alloc] initWithFrame:CGRectMake(0,0,20,20)];
UILongPressGestureRecognizer *longpressGesture1 = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(tapped:)];
[v addGestureRecognizer:longpressGesture1];
这里是处理手势识别器的代表。
-(IBAction)tapped:(UILongPressGestureRecognizer *) gesture
{
switch ([gesture state]) {
case UIGestureRecognizerStateBegan:
{
NSLog(@"Long Tap detacted.");
}
break;
case UIGestureRecognizerStateChanged:
{
NSLog(@"UIGestureRecognizerStateChanged");
}
break;
case UIGestureRecognizerStateEnded:
{
NSLog(@"Long Tap ended.");
}
break;
}
}
这段代码在 iOS 4 和 5 中按预期完美运行,但在具有视网膜显示的 ios 6 中,当我们执行长按时,UIGestureRecognizerStateBegan
一次长按会被调用两次,从而导致应用程序崩溃。非常欢迎任何帮助。