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

标签 ios iphone ios5 ios4 ios7

我正在制作一个应用程序,我希望在其中双击键盘,我通过使用文本字段委托(delegate)方法禁用了单击键盘:

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

然后我为文本字段创建了一个操作方法

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

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

[textField1 becomeFirstResponder];

但这行不通

建议我,我该怎么做?

最佳答案

首先创建一个 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;
}

关于ios - 如何在文本字段上双击键盘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21967626/

相关文章:

ios - 使用自动布局时,旋转一圈后我没有得到正确的响应

iphone - 奇怪的 iOS 内存分配行为

objective-c - 自动引用计数 : Pointer to non-const type 'NSError *' with no explicit ownership

iphone - 如何实现 iOS 金属探测器应用程序?

iphone - 如何在UIStepper上实现KVO

ios - Sqlite for iOS 是用哪种线程模式编译的?

iphone - CGContextClearRect 带圆圈

ios - AVPlayer - 播放音量非常低

ios - 每次重新安装应用程序时,供应商标识符都会发生变化

ios - 删除或卸载以前添加的库 : cocoapods