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?

AgentCorleone
  • 90
  • 1
  • 6

2 Answers2

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.

bentford
  • 33,038
  • 7
  • 61
  • 57
  • That's exactly what I figured, and you're right it makes perfect sense. Thanks! – AgentCorleone Dec 09 '11 at 08:19
  • Erm, doesn't this result in an "endless layouting loop"? So once `layoutSubviews` is called it will get called with every runloop iteration. – DarkDust Jun 21 '12 at 14:11
  • My test didn't loop, I can verify again, I'll dig up my example code I wrote when writing this answer. – bentford Jul 02 '12 at 19:35
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 =)

MightyPixel
  • 111
  • 1
  • 8