UIScrollView layoutSubviews behavior changes in iOS 5?
Asked Answered
T

2

2

I'm working on a component that is a subclass from UIView and contains a UIScrollView. When scrolling, I noticed different behaviors depending on which SDK I build with. On iOS 4 the layoutSubviews message is send on the scroll view's superview (which is my component) but on iOS 5 it seems that the message is not send anymore...

After taking a look at the iOS 5 release notes and changelog, I did not find any mention of such a change. Did I miss somethin?

Tabber answered 7/11, 2011 at 12:24 Comment(0)
V
5

In iOS5, layoutSubviews is not called on a scrollView's superview. But it was in iOS4.

If you want this behavior in iOS5, do this in your subclass of UIScrollView:

- (void)layoutSubviews {
    [super layoutSubviews];

    // causes layoutSubviews to get called on superview
    [self.superview setNeedsLayout]; 

This was probably changed to be more efficient. Just because UIScrollView is scrolling, doesn't mean it's superview needs to layout itself.

Vernita answered 3/12, 2011 at 20:36 Comment(3)
That's exactly what I figured, and you're right it makes perfect sense. Thanks!Tabber
Erm, doesn't this result in an "endless layouting loop"? So once layoutSubviews is called it will get called with every runloop iteration.Ceiba
My test didn't loop, I can verify again, I'll dig up my example code I wrote when writing this answer.Vernita
H
0

I had big probs with resizing the size of button witch was subview in tableview. The nib loaded the smaller button and after loading I resize it. But the table view content didn't. (In iOS 4.* it was perfect but in iOS 5). So I figured out that I have to place my resizing in ViewDidLoad. I hope it helps to some1 =)

Harding answered 27/4, 2012 at 16:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.