5

I have a nib that I originally created for an iPhone app with dimensions 320x480 and with autoresizing masks set up to expand the view in every direction should its superview be large.

I am now making my app universal, and am using the same nib and showing it in a page sheet on the iPad.

My problem is that I make some calculations based on the frame size, which is still showing 320x480. But in other methods, the frame size is showing correctly as the size of the page sheet.

Question: When do the autoresizing masks take effect so I can make my calculations at the correct time?

Scott
  • 115
  • 1
  • 2
  • 6

2 Answers2

3

The autoresizingMask property takes effect when the frame of it's superview changes. The superview property resizesSubviews must be YES. When you load your NIB, the superview's frame is set as in the NIB. You can set this to whatever you want while initializing.

XJones
  • 21,959
  • 10
  • 67
  • 82
  • 1
    I am presenting this view controller's view in a modal page control sheet. At *some* point the autoresizing masks take effect, I see that visually. But in viewDidLoad I don't see those reflected changes. Perhaps if I did those initial calculations in viewDidAppear as opposed to viewDidLoad it might do the trick? – Scott Apr 20 '11 at 21:40
  • Try overriding `layoutSubviews` instead. `viewDidLoad` only loads the subviews, it doesn't do layout. – XJones Apr 20 '11 at 21:57
  • 1
    Seems that the changes take effect in or around the next run loop after viewDidLoad gets executed. Not sure of the specifics, but I extracted out the layout stuff from viewDidload, put it in its own method, and can now call that from any number of places, including layoutSubviews, or viewWillAppear. Thanks! – Scott Apr 20 '11 at 23:20
  • 1
    sure thing. You should really only need to worry about layout in `layoutSubviews`. If you need to force a layout call `[view setNeedsLayout]` at any time. – XJones Apr 20 '11 at 23:55
0

It has been a long time since I've done something with development for the iOS, but I remember it mattered when rotating views when the device's rotation changes. So when you setup a view controller that will enable all device orientations, it will set the frame of it's view. That view will at his turn set all the subviews' frames. It'll look at the autoresizing mask to check how it has to alter the frame.

I'm not sure about this, but I thought it was something like this. Test it and let us know!

ief2

v1Axvw
  • 3,054
  • 3
  • 26
  • 40