2013-02-28 53 views
1

这段代码运行起来,直到我将我的项目从ios4转换为ios6(+ ARC)并将我的xib文件交换为故事板。现在我所做的任何点击都被视为长按。为什么我的常规点击被选为LongPresses?

手势设置

- (void)viewDidLoad 
{ 

[super viewDidLoad]; 

for(UIButton *button in buttons) 
{ 
    UILongPressGestureRecognizer *longPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressDetected:)]; 
    longPressRecognizer.minimumPressDuration = 1; 
    longPressRecognizer.numberOfTouchesRequired = 1; 
    [button addGestureRecognizer:longPressRecognizer]; 
} 

}

长按方法

- (IBAction)longPressDetected:(UIGestureRecognizer *)sender 
{ 
    if (sender.state != UIGestureRecognizerStateBegan) 
    { 
     NSLog(@"duplicate press cancelled"); 
     return; 
    } 
    NSLog(@"LongPress Received"); 
} 

故事板 enter image description here

+0

如果您删除'longPressRecognizer.minimumPressDuration = 1;'部分,是否有区别?也可以尝试将其更改为“1.0f”而不是“1”。 – iDev 2013-02-28 01:44:53

+0

@ACB既不工作。这个问题可能与IBActions如何关联?这在使用故事板之前工作得很好。 – Deco 2013-02-28 18:29:21

+0

这些按钮动作设置在哪里? – iDev 2013-02-28 18:31:26

回答

1

按你所添加的截图,你在故事板链接按钮来longPressDetected:。你需要在故事板中删除它,它会正常工作。

基本上它正在执行也指向相同方法的按钮操作。

1

更换你的代码,这一点,然后检查:

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

我很害怕,不行。 – Deco 2013-02-28 18:24:16

相关问题