Я добавил UIView в раскадровку (называемый swipedView), и я не задавал никаких ограничений автомакета. Ничего. Теперь в коде я хочу добавить некоторые ограничения. Чтобы проверить это, я хочу привязать его по сторонам экрана (так что это полноэкранный режим).Создать ограничения с кодом - получить ошибку «Невозможно одновременно удовлетворить ограничениям»
Когда я бегу, я получаю сообщение длинную ошибку, что-то вроде:
2016-07-18 22:59:07.990 FindTheWay[87145:18423835] 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.
(
"<NSLayoutConstraint:0x7ff02d11a6e0 V:|-(0)-[UIView:0x7ff02b479a40] (Names: '|':UIView:0x7ff02b450100)>",
"<NSIBPrototypingLayoutConstraint:0x7ff02b416a50 'IB auto generated at build time for view with fixed frame' V:|-(20)-[UIView:0x7ff02b479a40] (Names: '|':UIView:0x7ff02b450100)>"
)
Will attempt to recover by breaking constraint
<NSIBPrototypingLayoutConstraint:0x7ff02b416a50 'IB auto generated at build time for view with fixed frame' V:|-(20)-[UIView:0x7ff02b479a40] (Names: '|':UIView:0x7ff02b450100)>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
Это мой ViewController
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var swipedView: UIView!
@IBOutlet weak var foregroundView: UIView!
override func viewDidLoad() {
super.viewDidLoad()
// that was a proposed fix to my problem I found in the internet. Didn't work
view.translatesAutoresizingMaskIntoConstraints = false
}
override func viewDidAppear(animated: Bool) {
let pinTop = NSLayoutConstraint(item: swipedView, attribute: .Top, relatedBy: .Equal, toItem: view, attribute: .Top, multiplier: 1.0, constant: 0)
let pinLeft = NSLayoutConstraint(item: swipedView, attribute: .Leading, relatedBy: .Equal, toItem: view, attribute: .Leading, multiplier: 1.0, constant: 0)
let pinRight = NSLayoutConstraint(item: swipedView, attribute: .Trailing, relatedBy: .Equal, toItem: view, attribute: .Trailing, multiplier: 1.0, constant: 0)
let pinBottom = NSLayoutConstraint(item: swipedView, attribute: .Bottom, relatedBy: .Equal, toItem: view, attribute: .Bottom, multiplier: 1.0, constant: 0)
NSLayoutConstraint.activateConstraints([pinTop, pinLeft, pinRight, pinBottom])
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
Я совершенно новой для настройки ограничений с помощью кода, так что я» Я не знаю, как с этим бороться. Я проверил несколько похожих вопросов, которые я нашел на stackOverflow, но ничего мне не помогло, к сожалению.
Пробовал, что. Хотя я не нашел такую функцию, только логическое значение для установки на false – Quantm
Вы пробовали вещь о 'NSIBPrototypingLayoutConstraint', на которую ссылались ссылки на ответ? – dan
Я тоже пробовал, да. И теперь это работает (мне пришлось что-то изменить, см. Ответ З.Гски). Я не знаю почему. Я собираюсь опубликовать ответ – Quantm