[英]iOS: Why do I need an x value Constraint for my View?
I have two views on an iPad in landscape. 我在风景秀丽的iPad上有两种观点。
One, let's call him Fred, is a 100 pixel height rectangle that shares the same width as the superview. 我们称其为Fred,这是一个100像素高的矩形,与超级视图共享相同的宽度。 Fred goes directly under the navigation bar.
弗雷德直接进入导航栏。
Two, let's call her Elize, is a square inside of Fred, sharing height. 两个,我们称她为Elize,是Fred内的一个正方形,共享高度。 Elize belongs almost all the way to the right of Fred, barring 8 pixels.
Elize几乎一直属于Fred的右边,除非有8个像素。
Here Fred is green and Elize Pink/Purple. 弗雷德(Fred)是绿色,艾莉兹(Elize)粉红色/紫色。
These are the constraints I have applied to Elize: 这些是我应用于Elize的约束:
Fred.Trailing = Elize.Trailing, with constant 8, priority 1000, and multiplier 1
Elize.Top = Fred.Top, with constant 0, priority 1000, and multiplier 1
Elize.Height = Fred.Height, with constant 0, priority 1000, and multiplier 1
Even with these constraints, Xcode gives me a red warning sign in my Document Outline, saying that Elize needs constraints for the x position. 即使有这些约束,Xcode也会在我的文档大纲中给我一个红色警告标志,表示Elize需要对x位置进行约束。 When I allow Xcode to choose this constraint for me, it chooses:
当我允许Xcode为我选择此约束时,它选择:
Elize.Leading = Fred.Leading, with constant 684, priority 1000, multiplier 1
This isn't good enough, because when I look at my Main Storyboard preview, Elize moves too much to the left, and is no longer in the right corner of Fred. 这还不够好,因为当我查看主故事板预览时,Elize向左移动太多,而不再位于Fred的右角。
How can I fix this? 我怎样才能解决这个问题?
解决此问题的一种方法是向Elize添加宽度约束。
我的解决方案:给Elize一个Elize.Width = Elize.Width, with constant (size of Elize; it is not polite to write this information), priority 1000, multiplier 1
的约束Elize.Width = Elize.Width, with constant (size of Elize; it is not polite to write this information), priority 1000, multiplier 1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.