UIView 自动调整资源大小
我一直致力于自动调整自定义 UIView 的大小,而 Apple 对此几乎没有什么可说的。更重要的是,根据SO反馈,苹果的文档在某些方面实际上是错误的。最后,尽管 Interface Builder 中有六个调整大小组件,setAutoresizingMask:
有六个调整大小组件,但它们似乎根本不相关。例如,在旋转设备时,在 IB 中设置宽度弹簧与将 autoresizingMask
设置为 UIViewAutoresizingFlexibleWidth
具有不同的效果。
有没有什么好的资源可以帮助您了解 iPhone 上如何调整大小?
编辑:
我了解Apple使用的基本概念,例如contentMode,并且我已经阅读了UIView文档。我正在寻找一些东西,可以更深入地解释 IB 设置在 SDK 中以编程方式提供的功能方面的作用。
I've been working on autoresizing a custom UIView and Apple has very little to say on this. What's more, based on SO feedback, Apple's documentation is actually wrong in some areas. Finally, even though there are six resizing components in Interface Builder and six for setAutoresizingMask:
they don't seem to correlate at all. For example, setting the width spring in IB has a different effect from setting the autoresizingMask
to UIViewAutoresizingFlexibleWidth
when rotating the device.
Are there any good resources for learning about how resizing works on the iPhone?
Edit:
I understand the basic concepts Apple uses such as contentMode, and I've read through the UIView documentation. I'm looking for something that explains a little more deeply what the IB settings do in terms of what's available in the SDK programmatically.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
将
autoresizingMask
设置为UIViewAutoresizingFlexibleWidth
,相当于设置宽度弹簧,加上 Interface Builder 中的左右支柱(支柱意味着边缘不灵活)。如果您想复制仅设置宽度弹簧而不设置左右支柱的行为,则必须将autoresizingMask
设置为UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleLeftMargin UIViewAutoresizingFlexibleRightMargin
setting the
autoresizingMask
toUIViewAutoresizingFlexibleWidth
, is equivalent to setting the width spring, plus both the left and right struts in Interface Builder (the struts mean that the edge is not flexible). If you wanted to replicate the behavior of only setting the width spring, but not the left and right struts, you would have to setautoresizingMask
toUIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin
我发现这篇文章有助于理解 iOS 自动调整大小。
http://www.techotopia.com/index.php/IOS_4_iPhone_Rotation,_View_Resizing_and_Layout_Handling
I found this post helpful in understanding iOS autoresizing.
http://www.techotopia.com/index.php/IOS_4_iPhone_Rotation,_View_Resizing_and_Layout_Handling
来自苹果:
因此,如果您想将视图定位到其超级视图的顶部和右侧,您可以应用如下蒙版:
From Apple:
So if you would like to position a view anchored to the top and right side of its superview, you might apply a mask like:
superview 具有 contentMode 和 autoresizesSubviews 等参数,所有这些参数都带有其子视图的 autoresizingMask 使得调整大小行为能够被
仔细阅读 http://developer.apple.com/library/ios/#documentation/ uikit/reference/UIView_Class/UIView/UIView.html
superview has such parameters as contentMode and autoresizesSubviews, wich all with autoresizingMask of its subviews makes resizing behavior
read attentively http://developer.apple.com/library/ios/#documentation/uikit/reference/UIView_Class/UIView/UIView.html
根据记录,我挠头一小时,因为我的单行 UILabel 不会自动调整字体大小以适应宽度。最后,这成功了:
我用谷歌搜索,似乎没有人澄清这个细节(每个人都告诉你标签应该是 1 行,设置 adjustmentFontSizeToFitWidth/minimumFontSize 等)。
也许这个属性的默认值改变了?我使用的是 iOS 4.3。
For the record, I scratched my head for an hour because my one-line UILabel just would NOT auto-adjust font size to fit width. Finally, this did the trick:
I googled and no one seems to clarify this detail (everyone tells you the label should be 1 line, set adjustsFontSizeToFitWidth/minimumFontSize etc.).
Perhaps this property's default value changed? I'm on iOS 4.3.