iOS — UITextView disable scrolling but enable touches

断了今生、忘了曾经 提交于 2019-12-30 08:01:50

问题


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.


回答1:


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




回答2:


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




回答3:


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.




回答4:


Swift 3

let textView = UITextView()
textView.isScrollEnabled = false


来源:https://stackoverflow.com/questions/4413248/ios-uitextview-disable-scrolling-but-enable-touches

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!