Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS -- UITextView disable scrolling but enable touches

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.

like image 583
William Jockusch Avatar asked Dec 10 '10 20:12

William Jockusch


3 Answers

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

like image 125
James Bedford Avatar answered Oct 02 '22 13:10

James Bedford


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

like image 42
William Jockusch Avatar answered Oct 02 '22 12:10

William Jockusch


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.

like image 37
Mark McDonald Avatar answered Oct 02 '22 12:10

Mark McDonald