如何在代码中的UITextViews上设置“User Interaction Enabled”

时间:2021-03-18 23:17:02

I have the following problem: I got a view with two text fields and a UITextView (non editable, but scrolling) to show some infos. When the keyboard is shown I slide the whole view up so both text fields and the keyboard are shown. When the user clicks outside of the text fields I hide the keyboard and move the view back down.

我有以下问题:我有一个视图有两个文本字段和一个UITextView(不可编辑但滚动)来显示一些信息。当键盘显示时,我向上滑动整个视图,以便显示文本字段和键盘。当用户在文本字段外部单击时,我隐藏了键盘并向下移动视图。

This works only if the user does not click on the UITextView to hide the keyboard. If I turn of "User Interaction Enabled" in IB it works but UITextView won't be scrollable.

仅当用户未单击UITextView以隐藏键盘时,此方法才有效。如果我在IB中启用“User Interaction Enabled”它可以工作,但UITextView将无法滚动。

How do I set the "User Interaction Enabled" in code so whenever the keyboard is shown I would disable it? Or is there a better way to solve this?

如何在代码中设置“User Interaction Enabled”,这样每当键盘出现时我都会禁用它?或者有更好的方法来解决这个问题吗?

tia Stefan

1 个解决方案

#1


18  

Set the userInteractionEnabled property:

设置userInteractionEnabled属性:

//UITextView *textView;
textView.userInteractionEnabled = YES;

#1


18  

Set the userInteractionEnabled property:

设置userInteractionEnabled属性:

//UITextView *textView;
textView.userInteractionEnabled = YES;