本文介绍了iPhone Textview不调用TouchesBegan的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Textfield,当我触摸屏幕上的其他位置时,它会隐藏键盘(通过我的TouchesBegan函数并辞职...等等).但是,当我触摸Textview时,TouchesBegan不会被调用,键盘也不会隐藏!有什么方法可以调用TouchesBegan来隐藏键盘?

I have a Textfield which hides the keyboard when I touch somewhere else on the screen (through my TouchesBegan function and resign...blah). But when I touch a Textview the TouchesBegan does not get invoked and the keyboard doesn't hide! Is there any way to invoke TouchesBegan in order to hide the keyboard?

推荐答案

还有一种简单的方法可以在touchesBegan上隐藏键盘:使用UITextView输入数据时.

There is also a easy way to hide the keyboard on touchesBegan: when you are using UITextView to enter the data.

第1步.确保在类声明时扩展了Textviewdelegate.

Step 1. Be sure that you have extended Textviewdelegate while class declaration.

第2步.将委托设置为self in view done加载功能.

step 2. set the delegate to self in view did load function.

- (void)viewDidLoad
{
    txtMyView.delegate = self;
}

步骤3.使用您的textView名称在touchesbegan函数中编写类似代码.

step 3. write the similer code in touchesbegan function with you textView name.

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
            [txtMyView resignFirstResponder];
        [super touchesBegan:touches withEvent:event];

}

感谢和问候.

这篇关于iPhone Textview不调用TouchesBegan的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 21:59
查看更多