Reputation: 18544
I am encountering a strange resizing behavior.
When I resize a UIView, it's subview's height goes to 0.
I would imagine that the following code would only resize the view - not it's subview.
NSLog(@"view = %@", view);
NSLog(@"subview = %@", subview);
CGRect frame = view.frame;
frame.size.height = 50;
view.frame = frame;
NSLog(@"view = %@", view);
NSLog(@"subview = %@", subview);
However, the above yields the following output:
view = <UIView: 0x97e68c0; frame = (0 0; 320 400); autoresize = RM+BM; layer = <CALayer: 0x97e5f10>>
subview = <UIView: 0xb87f510; frame = (0 0; 320 50); autoresize = W+H; layer = <CALayer: 0xb87f020>>
view = <UIView: 0x97e68c0; frame = (0 0; 320 50); autoresize = RM+BM; layer = <CALayer: 0x97e5f10>>
subview = <UIView: 0xb87f510; frame = (0 0; 320 0); autoresize = W+H; layer = <CALayer: 0xb87f020>>
Any thoughts?
Upvotes: 0
Views: 1678
Reputation: 119021
The key is this section in the log output:
autoresize = W+H;
This is the log description of the UIView
-autoresizingMask
. Check the documentation here.
Basically, it's the way you describe what subviews should do when the superview is resized. It's very powerful.
Your current rules tell the subview to resize width and height when the superview is resized, and to keep the distance above and below the subview static (in terms of the superview coordinate system). Because the subview isn't very high, and you're resizing the superview a lot, the subview drops to zero height to try to maintain the above and below distances.
Upvotes: 3