开发者

autoresizingMask for fixed margin sizes

开发者 https://www.devze.com 2023-01-12 12:26 出处:网络
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:

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:

autoresizingMask for fixed margin sizes

autoresizingMask for fixed margin sizes

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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消