Iphone 为什么我的定期点击被选为长按?

Iphone 为什么我的定期点击被选为长按?,iphone,ios,objective-c,xcode,uigesturerecognizer,Iphone,Ios,Objective C,Xcode,Uigesturerecognizer,这段代码一直在运行,直到我将我的项目从ios4转换为ios6(+ARC),并将我的xib文件交换为故事板。现在我所做的任何点击都算作长按 手势设置 } 长压法 情节提要 将您的代码替换为此,然后检查: UILongPressGestureRecognizer *longPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressDetected:)];

这段代码一直在运行,直到我将我的项目从ios4转换为ios6(+ARC),并将我的xib文件交换为故事板。现在我所做的任何点击都算作长按

手势设置

}

长压法

情节提要

将您的代码替换为此,然后检查:

UILongPressGestureRecognizer *longPressRecognizer = [[UILongPressGestureRecognizer alloc]  initWithTarget:self action:@selector(longPressDetected:)];
longPressRecognizer.minimumPressDuration = 2.0;
longPressRecognizer.delegate = self;
[button addGestureRecognizer:longPressRecognizer];

根据您添加的屏幕截图,您已将按钮链接到故事板中的
longPressDetected:
。你需要在情节提要中删除它,它就会正常工作


基本上,它是在执行同样指向同一方法的按钮操作。

如果删除
longPressRecognizer.minimumPressDuration=1零件,有什么区别吗?还可以尝试将其更改为
1.0f
,而不是“1”。@ACB都不起作用。问题是否可能与iBaction之间的联系有关?在使用故事板之前,此操作效果良好。这些按钮操作设置在何处?@ACB位于LongPress检测到的方法中,并在故事板中链接:看起来您已将按钮链接到故事板中的此操作。在故事板中删除它,它将正常工作。
- (IBAction)longPressDetected:(UIGestureRecognizer *)sender 
{
    if (sender.state != UIGestureRecognizerStateBegan) 
    {
        NSLog(@"duplicate press cancelled");
        return;
    }
    NSLog(@"LongPress Received");
}
UILongPressGestureRecognizer *longPressRecognizer = [[UILongPressGestureRecognizer alloc]  initWithTarget:self action:@selector(longPressDetected:)];
longPressRecognizer.minimumPressDuration = 2.0;
longPressRecognizer.delegate = self;
[button addGestureRecognizer:longPressRecognizer];