如何在文本字段上双击键盘

时间:2014-02-23 11:31:21

标签: ios iphone ios5 ios4 ios7

我正在创建一个应用程序,其中我想要双击键盘,我通过使用textfield委托方法在单击时禁用了键盘:

-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField 
{
    return NO; 
}

之后我为textfield创建了一个动作方法

[textField1 addTarget:self action:@selector(clicked) forControlEvents:UIControlEventTouchDownRepeat];

在这种方法中,我使用了这段代码:

[textField1 becomeFirstResponder];

但这不起作用

建议我,我该怎么办?

2 个答案:

答案 0 :(得分:1)

首先创建一个Bool类型的类变量(比如BOOL shouldFire)并将其初始化为NO。 并将UITapGestureRecognisernumber of taps = 2添加到UITextField。

当连接到TapGesture的选择器触发时,请使用以下代码

-(void)tapped:(UITapGestureRecogniser *)ges{
 _shouldFire=YES;
 [textField1 becomeFirstResponder];
}

将您的方法更改为>

-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField 
{   
    if(self.shouldFire==YES){
      self.shouldFire=NO;
      return YES: 
    }
    return NO;
}

答案 1 :(得分:0)

很直接的建议是添加一个静态变量

-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField 
{
    static int count = 0;
    count++;
    if(count%2 ==0)
        return YES;
    else 
        return NO;
}
相关问题