views:

209

answers:

2

I am continuously appending text to the content of my UITextView and would like to auto-scroll to the latest update, only if if the UITextView has already been scrolled to the bottom. Any ideas on how this could be implemented?

+1  A: 

UITextView inherits from UIScrollView, so you can therefore access all of the same properties as with a UIScrollView. Personally, I would use a combination of

 myScrollView.contentOffset.y 

to detect whether or not the text is scrolled all the way down, and

[myScrollView zoomToRect:CGRectMake(x,y,height,width) animated:YES] 

to shift the current view to the newly added text.

See the docs for UITextView and UIScrollView. If you didn't know already, those can be accessed from XCode by clicking Help>>Developer Documentation

Good Luck!

James

James
A: 

To all those who want to automatically scroll a uitextview when a keyboard appears/ disappears, search and download keyboardaccessory.xcodeproj by apple. Although the program tests in an ipad simulator, you can copy the parts of the code and paste them in yours. Specifically: 1. copy the code on listening for the 2 notifications for keyboardWillShow and keyboardWillHide in the viewDidLoad. 2. copy the code releasing the notification in dealloc. 3. remove notification listening status in viewDidDisappear. 4. copy the codes in keyboardWillShow, keyboardWillHide to programmatically compute for the height of the keyboard and scroll the text automatically. 5. remove the keyboard in textViewShouldEndEditing by calling [textView resignFirstResponder]; 6. if you want this implemented in both portrait and landscape, the code above will already do the necessary computations. all you have to do is allow rotation in shouldRotateToInterfaceOrientation

meo