У меня есть расширение клавиатуры, которое начинается с постоянной высоты 280. Я даю ему ограничение по высоте с помощью кода ниже. Я называю это в viewWillAppear.Изменение высоты расширения клавиатуры динамически
func normalHeight() {
constant = 280
UIView.animateWithDuration(1.0) {
let heightConstraint = NSLayoutConstraint(item: self.view, attribute: .Height, relatedBy: .Equal, toItem: nil, attribute: .NotAnAttribute, multiplier: 0.0, constant: self.constant)
heightConstraint.priority = self.normalHeightPriority
self.view.addConstraint(heightConstraint)
}
self.view.setNeedsUpdateConstraints()
self.view.setNeedsDisplay()
}
Я также оживляю увеличение ограничения высоты с помощью кода, ниже которого также работает. Высота увеличивается.
func extendedHeight() {
constant = 400
UIView.animateWithDuration(1.0) {
let heightConstraint = NSLayoutConstraint(item: self.view, attribute: .Height, relatedBy: .Equal, toItem: nil, attribute: .NotAnAttribute, multiplier: 0.0, constant: self.constant)
heightConstraint.priority = self.extendedHeightPriority
self.view.addConstraint(heightConstraint)
}
self.view.setNeedsUpdateConstraints()
self.view.setNeedsDisplay()
}
Чтобы вернуть высоту, я снова вызываю normalHeight() с кнопки, и это не работает. Я подумал, что, возможно, приоритетными были проблемы, поскольку ограничение extendeHeight имеет приоритет 1000, а ограничение normalHeight имеет приоритет 999. Поэтому я перехожу к приоритетам, когда функции вызываются, как показано ниже. Еще нет кубиков.
func normalHeight() {
constant = 280
normalPriority = 1000
extendedPriority = 999
UIView.animateWithDuration(1.0) {
let heightConstraint = NSLayoutConstraint(item: self.view, attribute: .Height, relatedBy: .Equal, toItem: nil, attribute: .NotAnAttribute, multiplier: 0.0, constant: self.constant)
heightConstraint.priority = self.normalPriority
self.view.addConstraint(heightConstraint)
}
print("Normal Height Called")
self.view.setNeedsUpdateConstraints()
self.view.setNeedsDisplay()
}
и на расширенном приоритете, как так
func extendedHeight() {
constant = 400
extendedPriority = 1000
normalPriority = 999
UIView.animateWithDuration(1.0) {
let heightConstraint = NSLayoutConstraint(item: self.view, attribute: .Height, relatedBy: .Equal, toItem: nil, attribute: .NotAnAttribute, multiplier: 0.0, constant: self.constant)
heightConstraint.priority = self.extendedPriority
self.view.addConstraint(heightConstraint)
}
self.view.setNeedsUpdateConstraints()
self.view.setNeedsDisplay()
}
Я буду признателен за любую помощь и понимание, почему это не работает. Спасибо