UIButton滑动而不是单击

时间:2012-11-05 09:44:44

标签: objective-c ios xcode

在运行我的应用程序时,按钮表现得很奇怪。而不是单击它们只对滑动作出反应。点击时它们会变蓝,但不会发生任何动作,如果我轻扫它们,它们会按照应有的方式行动。在模拟器上,一切都按照预测的方式点击。我还没有实现任何滑动按钮等的方法。可能是什么问题?

更新:

 forControlEvents:UIControlEventTouchUpInside];
[save addTarget:self action:@selector(saveInfo)


forControlEvents:UIControlEventTouchUpInside];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]
                               initWithTarget:self
                               action:@selector(dismissKeyboard)];
[TableControll.view addGestureRecognizer:tap];


-(void)dismissKeyboard {
    [[_textFields objectAtIndex:0] resignFirstResponder];
    [[_textFields objectAtIndex:1] resignFirstResponder];
    [[_textFields objectAtIndex:2] resignFirstResponder];
    [[_textFields objectAtIndex:3] resignFirstResponder];
}

在不关闭键盘的情况下,按钮工作正常,那么如何让它们在没有问题的情况下一起工作呢?

2 个答案:

答案 0 :(得分:1)

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

    if ([touch.view isKindOfClass:[UIButton class]]) {
        return NO;
    }
    return YES;
}

使用此方法区分点击事件和按钮事件...

答案 1 :(得分:0)

我有类似的问题,这是我的解决方案:

tapRecognizer.cancelsTouchesInView = false