单击textfield IOS时隐藏键盘

单击textfield IOS时隐藏键盘,ios,uiview,uitextfield,Ios,Uiview,Uitextfield,我正在开发一个应用程序,在该应用程序中,我将从自定义视图(非输入视图)向文本字段输入数据。问题是,我不希望在触摸文本字段时系统键盘弹出。我已经完成了操作,但找不到解决方案。如何实现此目的。设置userInteractionEnabled属性: //UITextField *text; text.userInteractionEnabled = NO; 设置userInteractionEnabled属性: //UITextField *text; text.userInteractionEna

我正在开发一个应用程序,在该应用程序中,我将从自定义视图(非输入视图)向文本字段输入数据。问题是,我不希望在触摸文本字段时系统键盘弹出。我已经完成了操作,但找不到解决方案。如何实现此目的。

设置userInteractionEnabled属性:

//UITextField *text;
text.userInteractionEnabled = NO;

设置userInteractionEnabled属性:

//UITextField *text;
text.userInteractionEnabled = NO;

不确定,你到底在期待什么。我希望您需要处理
UITextField
委托,但不处理
UIKeyboard
:如果是这样,则实现的
delegate

-(void)textFieldDidBeginEditing:(UITextField *)sender{  
// resign the textfield and do your stuff with the data 
}

不确定,你到底在期待什么。我希望您需要处理
UITextField
委托,但不处理
UIKeyboard
:如果是这样,则实现的
delegate

-(void)textFieldDidBeginEditing:(UITextField *)sender{  
// resign the textfield and do your stuff with the data 
}

将IBOutlet属性分配给该特定UITextField
然后在viewDidLoad中添加以下代码
[self.YourUITextField setUserInteractionEnabled:NO]

将IBOutlet属性分配给该特定UITextField
然后在viewDidLoad中添加以下代码
[self.YourUITextField setUserInteractionEnabled:NO]

尝试此代码可能会对您有所帮助

-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField{

if (textField==/**urs testField on which you want to remove keyboard on click*/ ) {
    [textField resignFirstResponder];
   //*its depend your requirement
    [here you can call yours custom view];
}
return YES;
}

根据要求进行调整。

尝试此代码可能会对您有所帮助

-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField{

if (textField==/**urs testField on which you want to remove keyboard on click*/ ) {
    [textField resignFirstResponder];
   //*its depend your requirement
    [here you can call yours custom view];
}
return YES;
}

根据要求进行调整。

禁用特定字段的编辑

-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField{

    if ([textField isEqual:myTextField]) {
        return NO;
    }
    return YES;
}  

禁用对特定字段的编辑

-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField{

    if ([textField isEqual:myTextField]) {
        return NO;
    }
    return YES;
}  

你也可以用手势

- (void)viewDidLoad {
    [super viewDidLoad];

    UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideKeyboard)];
    gestureRecognizer.cancelsTouchesInView = NO;
    [self.view addGestureRecognizer:gestureRecognizer];
}

- (void)hideKeyboard {
    [self.view endEditing:YES];
}

你也可以用手势

- (void)viewDidLoad {
    [super viewDidLoad];

    UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideKeyboard)];
    gestureRecognizer.cancelsTouchesInView = NO;
    [self.view addGestureRecognizer:gestureRecognizer];
}

- (void)hideKeyboard {
    [self.view endEditing:YES];
}

那么为什么不使用UILabel?[self.textfield setUserInteractionEnabled:否];是的,我本可以用,但现在我对textfield做了很多修改…我得到了一个解决方案…你能告诉我否决这个问题的原因吗?这样我就可以提高我的标准吗?我不认为这个问题很愚蠢。看到答案的数量…为什么不使用UILabel?[self.textfield setUserInteractionEnabled:no];是的,本来可以用,但现在我已经用textfield做了很多修改…我找到了一个解决方案…你能告诉我否决这个问题的原因吗?这样我就可以提高我的标准吗?我不认为这个问题很愚蠢。看答案的数量…你能添加一些文字来解释这个问题的作用吗?它可能会解决眼前的问题,但目前不是很有教育意义。谢谢;)[self.view endEditing:是];//此语句将隐藏键盘。当我们使用许多基于标记值的文本字段时,这很有用。你能添加一些文本来解释它的作用吗?它可能会解决眼前的问题,但目前不是很有教育意义。谢谢;)[self.view endEditing:是];//此语句将隐藏键盘。当我们使用许多基于标记值的文本字段时非常有用。