Attribute Unavailable warning on iOS versions prio

2019-01-17 07:44发布

问题:

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.

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

回答1:

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.



回答2:

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.

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.



回答3:

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

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.



回答4:

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:

  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".



回答5:

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.

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.

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