如何在UITextview上的点击事件中停止keyBoard外观? [英] How To Stop keyBoard Appearence at click event on UITextview?

查看:108
本文介绍了如何在UITextview上的点击事件中停止keyBoard外观?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的IPad应用程序中,我只使用TextView进行文本显示。因为我需要显示较大的文本数据为什么我使用UITextview因为它的滚动属性而不是使用UILabel。
在我的应用程序中,我不需要在UITextview中编辑文本,但问题是,当我点击Textview滚动键盘时,它隐藏了我的textview,所以我想我的键盘永远不会出现在点击事件上。我进行了搜索,但没有找到任何合适的解决方案。任何帮助将被适用。谢谢

In my IPad Application i am using TextView only for Text Displaying.As i need to display a Larger Text Thats Why i am using UITextview due to its Scrolling Property instead of using UILabel. In my application i do not need to edit Text in UITextview ,but problem for me is that when i click on Textview for scrolling the keyboard appear its hide my textview so i want that my keyboard is never appear on click event.i make a search but not find any Suitable solution.Any help will be appriated.Thanx

推荐答案

新的答案(前一个工作不正常)

NEW ANSWER (previous one was not working properly)

好的,因为它不起作用,因为它也禁用了滚动,你应该尝试:

OK so since that is not working because it disables scrolling also, you should try to:

实现UITextFieldDelegate协议
在视图控制器中添加文本

Implement UITextFieldDelegate protocol In your view controller add the text

@interface YourViewController () <UITextViewDelegate>

在viewDidLoad中将自己设置为委托:

In viewDidLoad set yourself as a delegate:

yourUITextView.delegate = self;

实施下面的委托方法:

- (BOOL)textViewShouldBeginEditing:(UITextView *)textView
{ 
   return NO; 
}

当textview即将编辑文本时,将自动调用此方法。它返回no,因此编辑将不会开始。

When the textview is about to edit the text, this method will be called automatically. It returns no, so the editing won't start.

从上一个答案中撤消更改非常重要:不要设置可编辑字段没有

It is very important that you undo the changes from the previous answers: Do not set the editable field to NO

我尝试了它并且它正在工作。希望它有所帮助!

I tried it and it's working. Hope it helps!

OLD ANSWER

当您声明变量时,或者在viewdidload方法中,将editable属性设置为NO:

when you declare the variable, or in your viewdidload method, set the editable property to NO:

yourUITextView.editable = NO;

[yourUITextView setEditable:NO]

这应该可以防止出现键盘。

That should prevent the keyboard from appearing.

这篇关于如何在UITextview上的点击事件中停止keyBoard外观?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆