自动首选最大版面宽度在8.0之前的iOS版本上不可用(Automatic Preferred Max Layout Width is not available on iOS versions pri

编程入门 行业动态 更新时间:2024-10-27 14:33:13
自动首选最大版面宽度在8.0之前的iOS版本上不可用(Automatic Preferred Max Layout Width is not available on iOS versions prior to 8.0)

我使用Xcode6 beta6打开了一个现有的iOS项目,Xcode列出了Storyboard和Xib文件的以下警告:

自动首选最大版面宽度在8.0之前的iOS版本上不可用

我尝试通过将宽度设置为显式来解决警告,如下所示:

然而,这并没有解决警告。 他们如何被删除?

I opened an existing iOS project with Xcode6 beta6, and Xcode lists the following warning for both Storyboard and Xib files:

Automatic Preferred Max Layout Width is not available on iOS versions prior to 8.0

I tried addressing the warning by setting the width as explicit like below:

Yet this didn't resolve the warnings. How can they be removed?

最满意答案

更新3: 如果您的部署目标设置为7.1,那么将numberOfLines设置为1的标签也可以触发此警告。 这是完全可重复的新的单视图项目。

重现步骤:

创建一个新的单视图,objective-c项目 将部署目标设置为7.1 打开项目的故事板 将标签放在提供的视图控制器上 将该标签的numberOfLines设置为2。 编

我提交了以下雷达: rdar://问题/ 18700567

更新2: 不幸的是,这在Xcode 6的发布版本中再次出现。请注意,您可以手动编辑storyboard / xib来解决问题。 查尔斯A.在下面的评论中:

值得一提的是,您很容易意外地引入此警告,并且警告本身并不能帮助您找到作为罪魁祸首的标签。 这在复杂的故事板中是不幸的。 您可以将故事板作为源文件打开,并使用正则表达式<label(?!.*preferredMaxLayoutWidth)以查找省略preferredMaxLayoutWidth属性/值的标签。 如果在这样的行上添加preferredMaxLayoutWidth =“0”,它与标记显式相同并设置值0。

更新1: 这个bug现在已经在Xcode 6 GM中修复了。

原始答案 这是Xcode6-Beta6和XCode6-Beta7中的一个错误,现在可以安全地忽略。

苹果开发者论坛的苹果工程师有这样的想法:

优选的最大布局宽度是UILabel上的自动布局属性,允许其自动垂直增长以适应其内容。 6.0之前的Xcode的版本将在设计时将多行标签的preferredMaxLayoutWidth设置为当前边界的大小。 如果水平布局发生变化,则需要在运行时手动更新preferredMaxLayoutWidth。

iOS 8增加了在运行时自动计算preferredMaxLayoutWidth的支持,这使得创建多行标签更加容易。 此设置与iOS 7不兼容。为了支持iOS 7和iOS 8,Xcode 6允许您在尺寸检查器中为preferredMaxLayoutWidth选择“自动”或“显式”。 你应该:

选择“自动”,如果定位iOS 8以获得最佳体验。 如果定位<iOS 8,请选择“显式”。然后可以输入要设置的preferredMaxLayoutWidth的值。 启用“显式”默认为您选中该框时的当前边界大小。

如果(1)您正在使用自动布局,则会显示警告,(2)为多行标签设置“自动”[您可以在尺寸检查器中检查标签],以及(3)部署目标<iOS 8。

似乎错误是这个警告出现在非自动布局文档中。 如果您看到此警告,而不使用自动布局,则可以忽略该警告。

或者,您可以使用故障单或xib上的文件检查器来解决问题,并将“Builds for”更改为“Build for iOS 8.0 and Later” Xcode文件检查器

Update 3: This warning can also be triggered by labels that have numberOfLines set to anything but 1 if your deployment target is set to 7.1. This is completely reproducible with new single-view project.

Steps to Reproduce:

Create a new single-view, objective-c project Set the Deployment Target to 7.1 Open the project's storyboard Drop a label onto the provided view controller Set the numberOfLines for that label to 2. Compile

I've filed the following radar: rdar://problem/18700567

Update 2: Unfortunately, this is a thing again in the release version of Xcode 6. Note that you can, for the most part, manually edit your storyboard/xib to fix the problem. Per Charles A. in the comments below:

It's worth mentioning that you can pretty easily accidentally introduce this warning, and the warning itself doesn't help in finding the label that is the culprit. This is unfortunate in a complex storyboard. You can open the storyboard as a source file and search with the regex <label(?!.*preferredMaxLayoutWidth) to find labels that omit a preferredMaxLayoutWidth attribute/value. If you add in preferredMaxLayoutWidth="0" on such lines, it is the same as marking explicit and setting the value 0.

Update 1: This bug has now been fixed in Xcode 6 GM.

Original Answer This is a bug in Xcode6-Beta6 and XCode6-Beta7 and can be safely ignored for now.

An Apple engineer in the Apple Developer forums had this to say about the bug:

Preferred max layout width is an auto layout property on UILabel that allows it to automatically grow vertically to fit its content. Versions of Xcode prior to 6.0 would set preferredMaxLayoutWidth for multiline labels to the current bounds size at design time. You would need to manually update preferredMaxLayoutWidth at runtime if your horizontal layout changed.

iOS 8 added support for automatically computing preferredMaxLayoutWidth at runtime, which makes creating multiline labels even easier. This setting is not backwards compatible with iOS 7. To support both iOS 7 and iOS 8, Xcode 6 allows you to pick either "Automatic" or "Explicit" for preferredMaxLayoutWidth in the size inspector. You should:

Pick "Automatic" if targeting iOS 8 for the best experience. Pick "Explicit" if targeting < iOS 8. You can then enter the value of preferredMaxLayoutWidth you would like set. Enabling "Explicit" defaults to the current bounds size at the time you checked the box.

The warning will appear if (1) you're using auto layout, (2) "Automatic" is set for a multiline label [you can check this in the size inspector for the label], and (3) your deployment target < iOS 8.

It seems the bug is that this warning appears for non-autolayout documents. If you are seeing this warning and not using auto layout you can ignore the warning.

Alternately, you can work around the issue by using the file inspector on the storyboard or xib in question and change "Builds for" to "Builds for iOS 8.0 and Later" Xcode file inspector

更多推荐

本文发布于:2023-08-07 15:51:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1464759.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:宽度   上不   版面   首选   版本

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!