Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIScrollView calls layoutSubviews() each time its scrolled

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

like image 543
Erik Avatar asked May 03 '10 18:05

Erik


1 Answers

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.

like image 165
texmex5 Avatar answered Sep 24 '22 08:09

texmex5