gpt4 book ai didi

swift - Xcode 显示冲突的约束

转载 作者:行者123 更新时间:2023-11-30 10:46:40 24 4
gpt4 key购买 nike

我有一个 View Controller ,主要由 2 个 View 组成。一个具有与 super View 对齐的前导、尾随和底部 anchor 以及与 super View 成比例的高度(0.25)的 ScrollView ,以及将前导顶部和尾随与 super View /安全区域对齐以及与另一个 View 底部对齐的 ScrollView 。

我在 xib 文件中定义了一个 View ,我使用 Bundle.main.loadNibNamed("VariantResultSlide",owner: self, options: nil)?.first 创建了多次 View 并添加它们到数组slides。我想将它们添加到我的 ScrollView 中:

for i in 0 ..< slides.count {
scrollView.addSubview(slides[i])

NSLayoutConstraint.activate([
slides[i].leadingAnchor.constraint(equalTo: (i==0) ? scrollView.leadingAnchor : slides[i-1].trailingAnchor),
slides[i].topAnchor.constraint(equalTo: scrollView.topAnchor),
slides[i].bottomAnchor.constraint(equalTo: scrollView.bottomAnchor),
slides[i].widthAnchor.constraint(equalTo: scrollView.widthAnchor),
slides[i].heightAnchor.constraint(equalTo: scrollView.heightAnchor)
])
if(i==slides.count-1) {
NSLayoutConstraint.activate([slides[i].trailingAnchor.constraint(equalTo: scrollView.trailingAnchor)])
}
self.updateResultSlides(index: i, vehicle: orderedVehiclesList[i])
}

但是 Xcode 给了我这样的错误:

2019-04-11 13:57:07.219263+0200 FleetView[545:190663] [LayoutConstraints] 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)
(
"<NSAutoresizingMaskLayoutConstraint:0x282cecbe0 h=-&- v=-&- FleetView.VariantResultSlide:0x107f214a0.height == UIScrollView:0x102919200.height + 99 (active)>",
"<NSLayoutConstraint:0x282c92300 FleetView.VariantResultSlide:0x107f214a0.height == UIScrollView:0x102919200.height (active)>"
)

而且幻灯片太大了。但我找不到任何地方可以为他们设置另一个约束。为什么会发生这种情况?

最佳答案

您的 View 实现了 topbottomheight 约束,因此显然它的 super View 需要调整大小 - 但由于约束而无法调整大小从自动调整大小蒙版自动创建。在您的 super View 中禁用它

yourViewsSuperview.translatesAutoresizingMaskIntoConstraints = false

关于swift - Xcode 显示冲突的约束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55632066/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com