Swift 编程约束下边距不起作用
Swift programatic constraints bottom margin not working
我正在尝试在 uiview 的底边距和滚动视图的底边距之间设置编程约束。然而,xcode 给了我一些错误,文本看起来最好是不合适,有时它根本不会出现
所以基本上我有一个大小为 400 的 uiview 和一个滚动视图作为父视图。
我正在尝试在滚动视图底部和 uiview 底部之间添加 300 的距离。我需要以编程方式执行此操作,因为无法判断在给定时间屏幕上会出现多少视图,因此我需要以编程方式更改它们之间的约束。
我的密码是
view.addConstraint(NSLayoutConstraint(
item:container1,
attribute:NSLayoutAttribute.Bottom,
relatedBy:NSLayoutRelation.Equal,
toItem:scrollFrame,
attribute:NSLayoutAttribute.Bottom,
multiplier:0,
constant:400)
)
但它不起作用...显然,在模拟器上,uiview 位于距顶部 400 处,或者当我增加常量时它向下移动(尝试使用 600)
Xcode 打印以下错误:
2015-03-25 12:38:13.342 GraficTest[6612:707546] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
"<NSLayoutConstraint:0x7be906b0 V:|-(48)-[UIView:0x7be8e780] (Names: '|':UIScrollView:0x7be90340 )>",
"<NSLayoutConstraint:0x7bfd80e0 V:[UIView:0x7be8e780(257)]>",
"<NSLayoutConstraint:0x7bf6a940 UIView:0x7be8e780.bottom == + 600>"
)
你能帮帮我吗?
非常感谢!
从错误消息中我可以推断出一些事情:
- 将 UIView 放置在距 UIScrollView 顶部 48 点的位置存在限制
- UIView 的高度限制为 257 点
- UIView 底部必须位于 UIScrollView 底部上方 600 点。
由于 UIScrollView 会有一些高度,假设是 X,从上面的限制来看,它应该是
X = 48 + 257 + 600 = 905
但这显然不是这种情况,因此布局系统无法满足所有约束。
通过从 UIView 中删除高度限制,您或许可以解决此问题。
我正在尝试在 uiview 的底边距和滚动视图的底边距之间设置编程约束。然而,xcode 给了我一些错误,文本看起来最好是不合适,有时它根本不会出现
所以基本上我有一个大小为 400 的 uiview 和一个滚动视图作为父视图。 我正在尝试在滚动视图底部和 uiview 底部之间添加 300 的距离。我需要以编程方式执行此操作,因为无法判断在给定时间屏幕上会出现多少视图,因此我需要以编程方式更改它们之间的约束。
我的密码是
view.addConstraint(NSLayoutConstraint(
item:container1,
attribute:NSLayoutAttribute.Bottom,
relatedBy:NSLayoutRelation.Equal,
toItem:scrollFrame,
attribute:NSLayoutAttribute.Bottom,
multiplier:0,
constant:400)
)
但它不起作用...显然,在模拟器上,uiview 位于距顶部 400 处,或者当我增加常量时它向下移动(尝试使用 600)
Xcode 打印以下错误:
2015-03-25 12:38:13.342 GraficTest[6612:707546] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
"<NSLayoutConstraint:0x7be906b0 V:|-(48)-[UIView:0x7be8e780] (Names: '|':UIScrollView:0x7be90340 )>",
"<NSLayoutConstraint:0x7bfd80e0 V:[UIView:0x7be8e780(257)]>",
"<NSLayoutConstraint:0x7bf6a940 UIView:0x7be8e780.bottom == + 600>"
)
你能帮帮我吗?
非常感谢!
从错误消息中我可以推断出一些事情:
- 将 UIView 放置在距 UIScrollView 顶部 48 点的位置存在限制
- UIView 的高度限制为 257 点
- UIView 底部必须位于 UIScrollView 底部上方 600 点。
由于 UIScrollView 会有一些高度,假设是 X,从上面的限制来看,它应该是
X = 48 + 257 + 600 = 905
但这显然不是这种情况,因此布局系统无法满足所有约束。
通过从 UIView 中删除高度限制,您或许可以解决此问题。