问题描述
我正在制作一个应用程序,我想要双击键盘,我通过使用textfield委托方法在单击时禁用了键盘:
I am making a application in which I want keyboard on double-tap, I have disabled keyboard on single tap by using textfield delegate method:
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
return NO;
}
之后我为textfield制作了一个动作方法
And after that I make a action method for textfield
[textField1 addTarget:self action:@selector(clicked) forControlEvents:UIControlEventTouchDownRepeat];
在这种方法中我使用了这段代码:
And in this method I used this code:
[textField1 becomeFirstResponder];
但这不起作用
建议我,我该怎么办?
推荐答案
首先创建一个Bool类型的类变量(比如说 BOOL shouldFire
)并将其初始化为NO。
并将 UITapGestureRecogniser
与点击次数= 2
添加到UITextField。
First create a class variable of type Bool (say BOOL shouldFire
) and initialise it to NO.And add UITapGestureRecogniser
with number of taps = 2
to the UITextField.
当连接到TapGesture的选择器触发时,使用下面的代码
When the selector attached to TapGesture fires, use below code
-(void)tapped:(UITapGestureRecogniser *)ges{
_shouldFire=YES;
[textField1 becomeFirstResponder];
}
并将您的方法更改为 - >
And change your method to->
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
if(self.shouldFire==YES){
self.shouldFire=NO;
return YES:
}
return NO;
}
这篇关于如何在文本字段上双击键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!