簡體   English   中英

如何在文本字段上雙擊獲取鍵盤

[英]How to get Keyboard on double tap on a text field

我正在制作一個需要雙擊鍵盤的應用程序,通過使用文本字段委托方法,我已禁用了單擊鍵盤:

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

然后,我為文本字段創建一個操作方法

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

在這種方法中,我使用了以下代碼:

[textField1 becomeFirstResponder];

但這不起作用

建議我,我該怎么辦?

首先創建一個Bool類型的類變量(例如BOOL shouldFire )並將其初始化為NO。 並將UITapGestureRecogniser number of taps = 2 UITapGestureRecogniser添加到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;
}

直接建議是添加一個靜態變量

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM