views:

444

answers:

1

Hi,

I subclassed UIScrollView (IPhone SDK) and overrode the (void)layoutSubviews; method. I noticed that each time the scrollView is scrolled, this method is called.

Is that the correct behaviour or do I have mistakes in my code? If it is the default behaviour, isn't this a performance killer?

Sincerely, heinrich

A: 

It is the correct behaviour and it should be used to get a custom layout of your subviews. I have used it several times and haven't had any performance issues eaven with hundreds of items added.

A cut-out from the documentation on that topic:

Subclasses can also be containers for other views. In this case, just override the designated initializer, initWithFrame:, to create a view hierarchy. If you want to programmatically force the layout of subviews before drawing, send setNeedsLayout to the view. Then when layoutIfNeeded is invoked, the layoutSubviews method is invoked just before displaying. Subclasses should override layoutSubviews to perform any custom arrangement of subviews.

texmex5
I see, thats the expected behaviour of a ScrollView. Thanks!
Heinrich
If this answer was helpful, maybe you could mark it as correct :P. Thanks!
texmex5