David M.
David M.

Reputation: 3685

autoresizingMask for fixed margin sizes

In a view containing several subviews, one of the subviews should remain a fixed, non-zero distance from the top and bottom of the superview. In these images, this view is shown in gray:

Portait

Landscape

According to the documentation, this view should have a mask of UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth. However, this causes the view to expand its height to take over the entire superview. How can the view be contained to fixed, but non-zero margins? Thanks.

Upvotes: 3

Views: 2978

Answers (1)

tc.
tc.

Reputation: 33592

UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth should work.

However, there's a bug with UIView auto-sizing when the parent view's height/width become small (and everything breaks when it becomes zero) — it might just be that UIView height/width can't go negative.

I've come across this problem when doing initWithFrame:CGRectZero; it might also happen if you use something like subview.frame = self.bounds when self.bounds is CGRectZero (or otherwise small).

My bruteforce debugging method would be to override setFrame: and setBounds: to add an NSLog.

Upvotes: 2

Related Questions