UITextView making containing UIScrollView scroll
UITextView making containing UIScrollView scroll
- Subject: UITextView making containing UIScrollView scroll
- From: Roland King <email@hidden>
- Date: Sat, 12 Mar 2011 18:19:23 +0800
My main view is a UIScrollView on which I have a hierarchy of other views, ending with some UITextViews. I found that when I change the properties of the UITextView, the UIScrollView scrolls itself all over the place, often ending up in a very odd location.
Having spent 3 days tearing bits of my application apart I ended up subclassing UIScrollView and overriding a bunch of methods to log what was going on, most of them were called on the animation thread, so that was useless, eventually I tracked down a call to setContentOffset:animated on the main thread, this is what was starting the whole scroll going.
What appears to be happening is that I'm changing the font on one of my UITextViews, that is then (because a UITextView is a UIScrollView itself) is trying to scroll, I assume, so the text which was showing stays in-place; however I have scrolling turned off for those UITextViews ( [UITextView setScrollEnabled:NO] ) because I really don't want them to scroll. From looking at the method names in the stack trace it would seem the UITextView is searching for a containing UIScrollView to scroll, and I can only assume that when it finds itself disabled for scrolling it heads on up through the parent views until it finds one which is enabled, and scrolls it.
#0 0x00006d7b in -[RKScrollViewSubclass setContentOffset:animated:] at /Users/rols/Documents/Code/C/RK/RK/RKScrollViewSubclass:270
#1 0x0012e3df in -[UITextView scrollRectToVisibleInContainingScrollView] ()
#2 0x0012e8b4 in -[UITextView webViewDidChange:] ()
#3 0x0000c9c0 in -[RKTextView observeValueForKeyPath:ofObject:change:context:] () <- The Font on a UITextView gets set here
I can't find anything in the documentation which suggests UITextViews do this, nor a way to prevent it. It seems that if I allow scrolling on the contained UITextViews, this problem goes away, but now I have the issue of scrolling embedded UITextViews which I didn't want (and I can't use UILabels because I do want the text to be editable, and yes I'm tracking the text edits carefully, mindful of the size of the view).
Has anyone seen any documentation talking about UITextViews inside UIScrollViews, or anything similar and is there a documented way to stop this happening.
I will now go put the application back together again, that was hard to find. _______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden