【发布时间】:2017-05-23 07:20:48
【问题描述】:
我正在尝试为约束设置动画,但它似乎影响了整个视图。这是我用来为约束设置动画的代码。
@IBOutlet weak var personHeight: NSLayoutConstraint!
func animateBackgroundHeight() {
print("animate")
UIView.animate(withDuration: 5.0, animations: {
self.personHeight.constant = 19 // personHeight is the IBOutlet to the constraint
self.view.layoutIfNeeded()
})
}
当动画开始时,视图中的所有东西都会移动,但我不知道为什么。我想要动画的是视图的高度,但不影响 TextField 或按钮。将 GreyView 视为 TextField 的背景元素。
这是一张图片,向您展示我正在尝试为哪个约束设置动画(绿色)
粉色框代表父视图。 灰盒是我试图为其高度设置动画的视图。 TextField 和按钮位于 Gray Box 对象的上方。
【问题讨论】:
-
@Rob,对问题进行了编辑,我希望它更简洁。
标签: xcode uiview uiscrollview swift3 nslayoutconstraint