2016-10-24 5 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

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

あなたが」上がらない:レイアウト制約をアニメーション化する適切な方法は、事前にそれらを変更し、だからあなたのコードは次のようになります(これは実際にそのレイアウトを更新するビューを告げる)あなたのアニメーションブロックでlayoutIfNeededを呼び出すことです「アニメーション化可能な」属性を変更することはできません。 traint属性ですが、これらのいずれでもありません。Animatable Properties

+0

これは当てはまりませんが、制約の変更をアニメートできます。 https://stackoverflow.com/questions/12622424/how-do-i-animate-constraint-changes –

関連する問題