开发者

UIScrollView calls layoutSubviews() each time its scrolled

开发者 https://www.devze.com 2022-12-29 14:44 出处:网络
I subclassed UIScrollView (IPhone SDK) and overrode the (void)layoutSubviews; method. I noticed that each time the scrollView is scrolled, this method is called.

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,开发者_JAVA百科 isn't this a performance killer?

Sincerely, heinrich


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消