iOS - UITextView禁用滚动但启用触摸

时间:2022-08-24 10:42:58

Is there any way to do this?

有没有办法做到这一点?

What I really want is a UITextField where I can control the location of the cursor. But as far as I can tell, that is impossible. So I am looking at using a UITextView. This does allow one to control the cursor location. But scrolling is getting in the way -- my text is scrolling here and there, and I don't want that.

我真正想要的是一个UITextField,我可以控制光标的位置。但据我所知,这是不可能的。所以我正在寻找使用UITextView。这确实允许人们控制光标位置。但滚动正在阻碍 - 我的文本在这里和那里滚动,我不希望这样。

4 个解决方案

#1


16  

UITextView is a subclass of UIScrollView, so you can prevent the view from scrolling by setting the property scrollEnabled to NO.

UITextView是UIScrollView的子类,因此您可以通过将属性scrollEnabled设置为NO来阻止视图滚动。

#2


9  

If I set scrollEnabled to NO and have an empty implementation of scrollRectToVisible:animated:, it appears to disable scrolling.

如果我将scrollEnabled设置为NO并且具有scrollRectToVisible:animated:的空实现,则它似乎禁用滚动。

#3


8  

Just set the UITextView’s content size to be less than or equal to its bounds, this will prevent scrolling and still accept touch events.

只需将UITextView的内容大小设置为小于或等于其边界,这将阻止滚动并仍然接受触摸事件。

#4


1  

Swift 3

斯威夫特3

let textView = UITextView()
textView.isScrollEnabled = false

#1


16  

UITextView is a subclass of UIScrollView, so you can prevent the view from scrolling by setting the property scrollEnabled to NO.

UITextView是UIScrollView的子类,因此您可以通过将属性scrollEnabled设置为NO来阻止视图滚动。

#2


9  

If I set scrollEnabled to NO and have an empty implementation of scrollRectToVisible:animated:, it appears to disable scrolling.

如果我将scrollEnabled设置为NO并且具有scrollRectToVisible:animated:的空实现,则它似乎禁用滚动。

#3


8  

Just set the UITextView’s content size to be less than or equal to its bounds, this will prevent scrolling and still accept touch events.

只需将UITextView的内容大小设置为小于或等于其边界,这将阻止滚动并仍然接受触摸事件。

#4


1  

Swift 3

斯威夫特3

let textView = UITextView()
textView.isScrollEnabled = false