UIScrollView calls layoutSubviews () every time it scrolls

I have subclassed UIScrollView (IPhone SDK) and redefined (void) layoutSubviews; method. I noticed that every time scrollView scrolls, this method is called.

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

Regards, Heinrich

+5
source share
1 answer

This is the correct behavior, and it should be used to get a custom layout of your subzones. I used it several times and had no performance issues with adding hundreds of elements.

Cutting from the documentation on this topic:

Subclasses may 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 before viewing before sending, send setNeedsLayout for presentation. Then when layoutIfNeeded is called, the layoutSubviews method is called only before display. Subclasses must override layoutSubviews to perform any custom layout of subviews.

+10
source

All Articles