Constraint Animation only partially animating causing what looks like a "jump"

时间:2016-07-28 20:23:36

标签: ios animation constraints core-animation

When using the system default animations everything works as expected. However, when changing a top position constraint inside of animateWithDuration, the view's height adjustment doesn't animate, it jumps. And then its position animates to the correct location.

Here is an example video showing the issue: http://www.screencast.com/t/GAEQiGIqS.

The bottom view is blue and you will see that when it needs to shrink it gets "detached" from the bottom of the containing view and then is animated until it contacts the bottom. I want the bottom view to stay locked to the bottom of the containing view. Any suggestions?

The vertical constraints are being setup as:

constraints += NSLayoutConstraint.constraintsWithVisualFormat("V:|[topView][bottomView]|", options: NSLayoutFormatOptions(rawValue: 0), metrics: metricsDict, views: viewDict)

_bottomViewTopConstraint = NSLayoutConstraint(item: bottomView, attribute: .Top, relatedBy: .Equal, toItem: self.view, attribute: .Top, multiplier: 1, constant: bottomViewMiddlePos)

The snap to closest target drop point is done by changing the _bottomViewTopConstraint constant and then invoking the animation:

self.view.layoutIfNeeded()
UIView.animateWithDuration((2.3).seconds) {
_bottomViewTopConstraint.constant = currentPosition + shortestDelta
   self.view.layoutIfNeeded()
}

There are NO errors reporting that constraints had to be broken. So the AutoLayout system is fine, but it doesn't correctly animate the height change caused by the position change.

0 个答案:

没有答案