使用系统默认动画时,一切都按预期工作 . 但是,在animateWithDuration中更改顶部位置约束时,视图的高度调整不会生成动画,而是会跳转 . 然后它的位置动画到正确的位置 .

以下是显示该问题的示例视频:http://www.screencast.com/t/GAEQiGIqS .

底部视图为蓝色,您将看到当需要缩小时,它会从包含视图的底部“分离”,然后进行动画处理,直到它与底部接触为止 . 我希望底部视图保持锁定在包含视图的底部 . 有什么建议?

垂直约束设置为:

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)

通过更改_bottomViewTopConstraint常量然后调用动画来完成对最近目标放置点的捕捉:

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

没有错误报告必须打破约束 . 因此AutoLayout系统很好,但它没有正确设置由位置变化引起的高度变化的动画 .