How do I (easily) delete a constraint in Interface

2019-03-17 02:43发布

问题:

Assume you've selected an object and you have the Size Selector in the Utilities panel open. You can see the list of constraints applied to the object. In the list of constraints you could click on the little gear and pick delete. You can't in Xcode 6.

There are still several ways to delete constraints in IB:

  • Find the constraint in the Document Outline and delete it that way (but it can be hard to find).
  • Click on the little bar in the storyboard and delete it that way (which can be hard to click on).
  • Double click on the constraint in the Size Selector which will open Attribute Inspector and highlight the constraint in the Document Outline. This can be a nuisance when you want to delete several.

Still, I miss ease of use of the gear delete feature and I'm wondering if it's still there in a similar fashion and I just can find it. While the other ways work, I find myself wasting lots of time especially when playing with the new Size Classes feature. So, find a easier way to delete them?

回答1:

In Xcode6 (Beta5) when I click on a particular constraint in the Size inspector, it acquires a thin blue border. The constraint can then be deleted using the backspace.



回答2:

The accepted answer is right, but there is so much frustration with selecting constraints that lay outside of selected view that I decided to add this tips as another answer.

I found incredible list of tips that helped me to solve this problem.

The problem:

  1. You select the view and Xcode shows related constraints.
  2. You try to choose the one that is outside of selected view.
  3. You fail (end with selecting the view beneath the constraint)

Soulution:

Click it with Shift+Ctrl pressed and you'll see a menu of all the views that exist where you've clicked.

To delete selected constraint press delete key.



回答3:

The selected answer is incomplete. When you delete the constraint from the Size Inspector, you are leaving behind the constraint object in the Document Outline pane. It is greyed out, meaning it is not used, but still exists and, what's worse, will affect auto layout with errors, warnings or conflicting constraints and you will go crazy until you also delete them from the Document Outline pane.

So:

1. Delete the constraint from the Size Inspector as in the accepted answer
2. Delete any greyed out constraints from the Document Outline

Live a happy, constraint-free life.



回答4:

This answer from @wayne chi is the simplest, and spares you from hunting down constraints in Document Outline:

Double click the grayed out constraint (switches focus to the constraint) then press delete. This will delete the constraint.



回答5:

Sometimes, the easiest way is to close the file in Xcode and edit it with a text editor. :-/



回答6:

If you want to delete ALL constraints from a viewController simply turn off auto layout and then reenable it (or don't) and all of the constraints will be gone.