2016-10-24 3 views
1

Я пытаюсь выполнить обновление структуры, со следующими линиями, но анимация стремительна, нет никакой задержки. Любая идея, почему? Использование 8.0 Xcode.Почему UIView.animate (withDuration не влияет?

UIView.animate(withDuration: 12.0, animations: { 

    self.yellowLineLeadingConstraint.isActive = false 
    self.yellowLineTrailingConstraint.isActive = false 

    self.yellowLineLeadingConstraint = NSLayoutConstraint(item: self.yellowLine, attribute: .leading, relatedBy: .equal, toItem: b, attribute: .leading, multiplier: 1.0, constant: 0) 
    self.yellowLineTrailingConstraint = NSLayoutConstraint(item: self.yellowLine, attribute: .trailing, relatedBy: .equal, toItem: b, attribute: .trailing, multiplier: 1.0, constant: 0) 

    self.view.addConstraints([self.yellowLineLeadingConstraint, self.yellowLineTrailingConstraint]) 

    self.yellowLineLeadingConstraint.isActive = true 
    self.yellowLineTrailingConstraint.isActive = true 
}) 
+1

Попробуйте добавить self.view.layoutIfNeeded –

ответ

4

правильный способ анимации ограничения макета, чтобы изменить их заранее, и вызвать layoutIfNeeded в вашей анимации блока (это говорит вид на самом деле обновить его макет) Так что ваш код будет выглядеть следующим образом:.

self.yellowLineLeadingConstraint.isActive = false 
self.yellowLineTrailingConstraint.isActive = false 

self.yellowLineLeadingConstraint = NSLayoutConstraint(item: self.yellowLine, attribute: .leading, relatedBy: .equal, toItem: b, attribute: .leading, multiplier: 1.0, constant: 0) 
self.yellowLineTrailingConstraint = NSLayoutConstraint(item: self.yellowLine, attribute: .trailing, relatedBy: .equal, toItem: b, attribute: .trailing, multiplier: 1.0, constant: 0) 

self.view.addConstraints([self.yellowLineLeadingConstraint, self.yellowLineTrailingConstraint]) 

self.yellowLineLeadingConstraint.isActive = true 
self.yellowLineTrailingConstraint.isActive = true 

UIView.animate(withDuration: 12.0, animations: { 
    self.view.layoutIfNeeded() 
} 
-2

Вы Арен» t меняет любые «анимирующие» атрибуты. Я вижу, вы обновляете свои минусы traint, но это не один из них Animatable Properties

+0

Это неправда, вы можете анимировать изменения ограничений. https://stackoverflow.com/questions/12622424/how-do-i-animate-constraint-changes –

Смежные вопросы