8.0 之前的 iOS 版本上的属性不可用警告

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25275901/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 01:49:06  来源:igfitidea点击:

Attribute Unavailable warning on iOS versions prior to 8.0

iosinterface-builder

提问by GLee

What's causing this warning in the interface builder?

是什么导致界面生成器中出现此警告?

Attribute Unavailable Layout attributes relative to the layout margin on iOS versions prior to 8.0.

属性 8.0 之前的 iOS 版本上相对于布局边距的布局属性不可用。

I'm using the XCode 6 Beta. The warnings are pointing to lines in the xml source that do not concern attributes.

我正在使用 XCode 6 Beta。警告指向 xml 源中与属性无关的行。

回答by GLee

Since I had already created the constraints, the answer was to click on the constraint, and then look in the Utilities bar (on the right). As shown in the picture below, click on an item and then make sure that "relative to margin" is unchecked.

由于我已经创建了约束,答案是单击约束,然后查看实用工具栏(右侧)。如下图所示,单击一个项目,然后确保取消选中“相对于边距”。

Relative to margin screenshot

相对保证金截图

回答by Tchelow

When you add constraints in Xcode 6, you have the option "Constrain to margins" which create a different constraint and can't be read, for example, in Xcode 5. Create the constraints without this options and the warnings should go away. This constraints will be available on iOS 8.

当您在 Xcode 6 中添加约束时,您可以选择“Constrain to margins”,这会创建一个不同的约束并且无法读取,例如,在 Xcode 5 中。创建没有此选项的约束,警告应该消失。此约束将在 iOS 8 上可用。

enter image description here

在此处输入图片说明

If you have already created the constraints, we can change it clicking on the constraint and editing it. When selecting the second item, you can uncheck the "Relative to margin" option (as explained in the GLee answer.

如果您已经创建了约束,我们可以通过单击约束并编辑它来更改它。选择第二项时,您可以取消选中“相对于保证金”选项(如 GLee 回答中所述。

回答by Collin

If you can't find where the warning is coming from you can use this grep to find it.

如果您找不到警告的来源,您可以使用此 grep 来查找它。

Run this in Terminal in your project directory:

在项目目录中的终端中运行它:

grep -C 6 -nr Margin .

The 6 says how many lines of context to show before and after the match.

6 表示在比赛前后显示多少行上下文。

回答by Kevin Kaiser

As per Gasper Kolenc opening the storyboard as Source Code is very useful. Here is a bit more info from my experience fixing this problem:

根据 Gasper Kolenc 的说法,打开故事板作为源代码非常有用。以下是我解决此问题的经验中的更多信息:

  1. In the storyboard source code search for "margin".You will see a line such as this.

    constraint firstAttribute="trailingMargin" secondItem="Pgb-8w-IHT" secondAttribute="trailing" constant="8" id="nKP-uZ-7Xm"/

  2. Find the id of one of the attributes (Pgb-8w-IHT in the example above).

  3. Scroll up to find in which object this constraint belongs. Something like:

    tableViewCell contentMode="scaleToFill" selectionStyle="default"

  4. Switch back to storyboard view and show the identity inspector window.

  5. Search through the subviews of the object you found above to find the id (Pgb-8w-IHT) on the identity inspector.

  6. Once found inspect the constraints to find the one that needs to be deleted and recreated without the constrain to margins option selected (use the constant=" " as a hint".

  1. 在故事板源代码中搜索“margin”。您将看到这样的一行。

    约束 firstAttribute="trailingMargin" secondItem="Pgb-8w-IHT" secondAttribute="trailing" constant="8" id="nKP-uZ-7Xm"/

  2. 找到其中一个属性的 id(上例中的 Pgb-8w-IHT)。

  3. 向上滚动以查找此约束属于哪个对象。就像是:

    tableViewCell contentMode="scaleToFill" selectionStyle="default"

  4. 切换回故事板视图并显示身份检查器窗口。

  5. 搜索您在上面找到的对象的子视图,以在身份检查器上找到 id (Pgb-8w-IHT)。

  6. 一旦找到,检查约束以找到需要删除和重新创建的约束,而不选择约束到边距选项(使用常量 =““作为提示”。

回答by user8925456

In my case, I had to uncheck the "Use Auto Layout" from my storyboard in the File Inspector, and redo all the constraints in my app, the old way with that shrinking / enlarging red rectangle.

就我而言,我必须在文件检查器的故事板中取消选中“使用自动布局”,并在我的应用程序中重做所有约束,使用缩小/放大红色矩形的旧方法。

Size Classes were already disabled and the target is IOS 7.1.

大小类已经被禁用,目标是 IOS 7.1。

But think well if you have too many View Controllers, and had already made all your constraints. When you disable auto layout, Xcode clears all the automatic constraints and reverts to the old model. Then you have to do all the job again.

但是如果你有太多的视图控制器,并且已经做了所有的约束,请好好想想。当您禁用自动布局时,Xcode 会清除所有自动约束并恢复到旧模型。然后你必须重新做所有的工作。

This was the only way I get rid of that Attribute Unavailable warning.

这是我摆脱该属性不可用警告的唯一方法。