在使用自动布局之前,我曾通过在项目中设置帧并使用animateWithDuration
来动画化背景的高度。
func setUpBackground() {
self.backgroundView.frame = CGRect(x: 0, y: 0, width: 320, height: 10)
self.backgroundView.backgroundColor = UIColorFromRGB(0x2d2d2d).CGColor
}
func AnimateBackgroundHeight() {
UIView.animateWithDuration(0.5, animations: {
self.backgroundView.frame = CGRect(x: 0, y: 0, width: 320, height: 600)
})
}
将我的项目转换为自动布局后,我注意到动画发生了,但是背景高度在动画后会回弹到原始大小/样式(界面生成器设置)。我阅读了当开启自动布局时,约束将覆盖使用CGRect
设置UIView
尺寸的设置。
因此,我想知道如何在开启自动布局的情况下实现相同的高度变化动画效果。