简体   繁体   English

iOS:为什么我的视图需要x值约束?

[英]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.

相关问题 为什么需要@ 1x,@ 2x和@ 3x iOS图像? - Why do I need @1x, @2x and @3x iOS images? 如何在 iOS 13.X 中以编程方式修复此约束? - How do I fix this constraint programmatically in iOS 13.X? 为什么在延迟后需要设置约束常量? - Why do I need to set constraint constant after some delay? 为什么我无法在视图上安装约束? - Why am I unable to install a constraint on my view? 屏幕上显示视图之前,应在哪里更新约束? - Where do I update my constraint before the view is on screen? iOS:如何使用整数值对表格视图进行排序,但想显示字符串值? - iOS: How do I sort my table view using a integer value but wanting to display a string value? 为什么我需要对字典中的字符串值进行字符串插值 - why i need to do a string interpolation to my string value in my dictionary 为什么我不需要为自定义UIViewController的根视图指定autoresizingMask? - Why do I not need to specify autoresizingMask for my custom UIViewController's root view? iOS:为什么我的模式视图上有白色的圆角? - iOS: Why do I have white, rounded corners on my modal view? 我们需要在iOS中动态调整视图高度的约束 - Which Constraint we need to make dynamic View height in iOS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM