自动首选最大布局宽度在 8.0 之前的 iOS 版本上不可用 [英] Automatic Preferred Max Layout Width is not available on iOS versions prior to 8.0

查看:22
本文介绍了自动首选最大布局宽度在 8.0 之前的 iOS 版本上不可用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

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 以外的任何标签触发.这完全可以通过新的单视图项目重现.

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.

重现步骤:

  1. 创建一个新的单视图、objective-c 项目
  2. 将部署目标设置为 7.1
  3. 打开项目的故事板
  4. 将标签拖放到提供的视图控制器上
  5. 将该标签的 numberOfLines 设置为 2.
  6. 编译

我已经提交了以下雷达:
rdar://problem/18700567

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

更新 2:
不幸的是,这在 Xcode 6 的发布版本中再次出现.请注意,在大多数情况下,您可以手动编辑故事板/xib 来解决问题.根据以下评论中的 Charles A.:

值得一提的是,您很容易意外地引入此警告,警告本身无助于查找罪魁祸首的标签.这在复杂的情况下是不幸的故事板.您可以将故事板作为源文件打开并搜索使用正则表达式 来查找标签省略 preferredMaxLayoutWidth 属性/值.如果你加入此类行上的 preferredMaxLayoutWidth="0" 与标记相同显式并将值设置为 0.

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.

更新 1:
此错误现已在 Xcode 6 GM 中修复.

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

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

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

Apple 开发者论坛中的一位 Apple 工程师this 谈到了这个错误:

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

首选最大布局宽度是 UILabel 上的自动布局属性允许它自动垂直增长以适应其内容.6.0 之前的 Xcode 版本会为在设计时将多行标签设置为当前边界大小.你会如果您需要在运行时手动更新 preferredMaxLayoutWidth水平布局已更改.

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 增加了对自动计算的支持运行时的 preferredMaxLayoutWidth,这使得创建多行标签更容易.此设置不向后兼容 iOS7. 为了同时支持 iOS 7 和 iOS 8,Xcode 6 允许您在大小中为 preferredMaxLayoutWidth 选择Automatic"或Explicit"检查员.你应该:

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:

如果面向 iOS 8 以获得最佳体验,请选择自动".挑选显式"如果定位

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.

如果 (1) 您正在使用自动布局,(2) 则会出现警告为多行标签设置了自动"[您可以在标签的尺寸检查器],以及 (3) 您的部署目标

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.

或者,您可以通过使用故事板或 xib 上的文件检查器来解决此问题,并将Builds for"更改为Builds for iOS 8.0 and later"

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"

这篇关于自动首选最大布局宽度在 8.0 之前的 iOS 版本上不可用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆