XCode 7 - Misplaced views warning for view in Stor

2019-09-12 08:18发布

问题:

I have added a UIView on storyboard in which i set a constraints to top,left,bottom,right as shown below

As you can see in the image, orange bordered line indicates that i misplaced the view.

My UIView position is 0,20,320,150. I am not sure why xcode shows the warning eventhough i set a correct constraint.

I am using Xcode 7 beta version.

回答1:

Your constraints doesn't respect you frame.
You have frame 0, 20, 320, 150, but constraints show Trailing Space: -20 and Leading Space: -20. Set both of them to -16 and warnings will disappear.
You need set -16 because your constraints related to margins, not to actual bounds. Margin has 16 points offset from bounds.