0
votes

Hopefully the following gives everything required.

There is a single line that adjusts the frame of a parent view in my app, and the affected subview is not responding in an appropriate manner according to my expectations for the autoresizingMask.

viewController.view subviews has 1 subview, with all margins resize, and the frame is 0,0,320,270.

viewController.view has frame = 0,0,320,276

after resizing viewController.view to 0,64,1024,704

the one subview is stuck to the bottom, basically the same effect as if there was no flexible bottom margin in the subview.

352,434,320,270. Proper size, it didn't resize. But 434 points down from the top of its superview, plus height 270, = 704, the height of superview.

I expect the 434 difference between the 270 subview height and 704 to be balanced between the top and bottom margin.

But both the top and bottom margins are specified to resize. I'm very puzzled. Could be I've gone code blind, and this is very easy.

Perhaps this has to do with some special handling when a margin is zero, but another margin is not zero. Haven't ever experimented with that case before.

po [viewController.view subviews]

(id) $1 = 0x09696340 <__NSArrayM 0x9696340>(

< UIView: 0x9695790; frame = (0 0; 320 270); autoresize = LM+RM+TM+BM; layer = < CALayer: 0x96957f0>>

)

(lldb) po viewController.view

(UIView *) $2 = 0x09695ab0 < UIView: 0x9695ab0; frame = (0 0; 320 276); autoresize = W+H; layer = < CALayer: 0x9695b10>>

Then one line of code to change the superview:

viewController.view.frame = {...};

(lldb) po viewController.view

(UIView *) $3 = 0x09695ab0 < UIView: 0x9695ab0; frame = (0 64; 1024 704); autoresize = W+H; layer = < CALayer: 0x9695b10>>

(lldb) po [viewController.view subviews]

(id) $4 = 0x09696340 <__NSArrayM 0x9696340>(

< UIView: 0x9695790; frame = (352 434; 320 270); autoresize = LM+RM+TM+BM; layer = < CALayer: 0x96957f0>>

)

Edit-

The problem may be another property is in effect that I'm unaware of. Perhaps something like autolayout or a constraint, but autolayout is turned off. Also, the superview is not a custom UIView subclass with something fancy in layoutSubviews. It's all plain UIKit stuff.

1
how did you add create the view and its subview from a nib file or, you created it programmatically? If by code then you need to set the subview's property autoresizingMask - otakuProgrammer
They're created from a nib. But It shouldn't matter right? I've created views from code and from nib and manually defined autoresizingMask in code and in nib, back and forth. The docs say the default value is UIViewAutoresizingNone - Tom Pace
I am wondering if there is another property that I am missing. Perhaps something to do with autolayout or a constraint is in effect, but autolayout is turned off. - Tom Pace
Also, the superview is not a custom UIView subclass with something fancy in layoutSubviews. It's all regular. - Tom Pace
I have confirmed: if a UIView has flex margins top+bottom, and static height, and frame.origin.y == 0, then when the superview is resized, the view is repositioned to the bottom. basically then frame.origin.y == superview.bounds.size.height - view.bounds.size.height. Very confusing, and counter-intuitive. - Tom Pace

1 Answers

0
votes

You are trying to add view from nib. So, as per my opinion, nib is executed very first when app is launched. At this time your view doesn't contain the actual size of the device or superview. So when app is launched, it'll take size of actual you defined, and it'll add subview of initial size.

So, my suggestion is to add view in ViewWillAppear() or ViewDidAppear(), Because at this time actual size of device is acquire and you will get proper size and position of the view.