Take the 2-minute tour ×

I've done some looking around but I haven't been able to find anything that clearly explains how I could simultaneously scroll two un-editable UITextViews. I think I may need to use either scrollRangeToVisible, or setContentOffset, though I could not get either of them to work.

Does anyone have any examples/samples, or documentation regarding this that they could point me towards?

EDIT: To clarify, I would like to be able to scroll one UITextView, and have the changes as a result of the scrolling reflected on a second UITextView as well.


share|improve this question
add comment

2 Answers

up vote 0 down vote accepted

React in

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{

and set the other's scrollView setContentVisible according to scrollView.contentOffset.

Just be aware that some methods of UIScrollView will invoke scrollViewDidScroll even if called programmatically. This applies to scrollRangeToVisible and will end up in a loop unless you take action to prevent this loop. I don't think that setContentOffset or setting scrollView2.contentOffset = CGPointMake(..,..) does call scrollViewDidScroll. However, I would not sign this in blood. Be prepared to see a loop and take actions to avoid it. (such as boolean instance variable set before calling setContentOffset and re-set in scrollViewDidScroll followed by return;)

share|improve this answer
Hmmm, maybe im misunderstanding what you mean, but let me clarify what I'm trying to achieve. What I would like to happen is to be able to scroll the content of one UITextView and have a second UITextView respond to the scrolling as well. I think with the UIScrollView I would be scrolling both of them without changing their content view, if I understand correctly. –  Karoly S Sep 1 '11 at 20:11
All right. I had given two answers at once because I was not sure, what you wanted. Answer edited accordingly. You will have to use two scroll views. In the first you need to react when it is scrolled and then programatically scroll the other one to the same extend (offset). Just avoid a loop. –  Hermann Klecker Sep 1 '11 at 22:48
add comment

Use the UIScrollViewDelegate methods to get information about scroll actions of the first scroll view and then scroll the second programmatically like that:

- (void) scrollViewDidScroll:(UIScrollView *)view1 {
    scrollView2.contentOffset = view1.contentOffset;
share|improve this answer
add comment

Your Answer


