iOS — UITextView disable scrolling but enable touc

2019-02-16 09:26发布

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.

4条回答
狗以群分
2楼-- · 2019-02-16 09:42

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.

查看更多
欢心
3楼-- · 2019-02-16 09:50

Swift 3

let textView = UITextView()
textView.isScrollEnabled = false
查看更多
老娘就宠你
4楼-- · 2019-02-16 10:01

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

查看更多
兄弟一词,经得起流年.
5楼-- · 2019-02-16 10:05

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

查看更多
登录 后发表回答