why does UIScrollView call layoutSubviews every time it scrolls?
why does UIScrollView call layoutSubviews every time it scrolls?
- Subject: why does UIScrollView call layoutSubviews every time it scrolls?
- From: Roland King <email@hidden>
- Date: Wed, 9 Feb 2011 00:15:57 +0800
Motivation: I have a view to display which is normally larger than the area it has to fit in (like UITextView which extends a UIScrollView) so my custom UIView is a UIScrollView subclass, the idea is that when setFrame: gets called, I will eventually get a layoutSubviews which calculates the required size of the contained UIView, sets its frame and also the contentSize of the scroll view.
However when I set it up like that I found that every single time the scrollview scrolls, it calls layoutSubviews on itself, performance goes to hell because the subview layout is complex and resetting the contentSize at the end seems to mess up the scrolling as well, ie the thing doesn't scroll, it just hiccups in the middle of the screen.
I can't see why UIScrollView would call layoutSubviews every time it scrolls, I expected that it would call layoutSubviews once only when its geometry changes (or you ask it to) and after that would just scroll its contained view quietly.
Currently I've worked around this by not using setNeedsLayout or layoutSubviews but instead having my own layout method I call synchronously when I know I need it (ie when setFrame: is called and at a few other points). This works but I expected to be able to use layoutSubviews for this and stay within the framework.
Is there something I've potentially missed here which is causing layoutSubviews to be called so often? Or should I never subclass a UIScrollView (it does have subclasses in the UI world) but instead embed it within a UIView which implements layoutSubviews but reaches down to its contained UIScrollView and lays out its subviews for it (which sounds awful). _______________________________________________
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