У меня есть контроллер вида, состоящий в основном из 2 видов.
Тот, у которого ведущий, задний и нижний якорь выровнены с суперпредставлением и пропорциональной высотой к суперпредставлению (0,25), и вид с прокруткой, который выравнивает переднюю вершину и трейлинг к суперпредставлению / безопасной области и снизу другого вида.
У меня есть представление, определенное в xib-файле, которое я создаю несколько раз с помощью Bundle.main.loadNibNamed("VariantResultSlide", owner: self, options: nil)?.first
и добавляю их в массив 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)>"
)
и слайды слишком большие.
Но я не могу найти место, где я бы поставил другое ограничение для них. Почему это происходит?