gpt4 book ai didi

ios - UIView 动画不动画

转载 作者:行者123 更新时间:2023-11-30 14:07:37 25 4
gpt4 key购买 nike

我有一段代码,可以对 UIImage 的位置进行动画处理,但是过渡不是动画的 - 相反,位置会立即发生变化。我不认为这是代码问题,因为相同的代码可以在另一个项目上运行,但我无法弄清楚还有什么问题。

class CenterViewController : UIViewController {
@IBOutlet var logoView: UIImageView!
@IBOutlet var logoViewVerticalConstraint: NSLayoutConstraint!

override func viewDidAppear(animated: Bool) {
animateLogo()
}

func animateLogo() {
self.logoViewVerticalConstraint.constant = 35 - (self.view.frame.size.height / 2);
logoView.setNeedsUpdateConstraints()
UIView.animateWithDuration(2.5, animations: {
self.logoView.alpha=1
self.logoView.layoutIfNeeded()
})
}
}

alpha 动画,但 y 位置不动画。我的约束看起来像这样

enter image description here

具体来说,代码中操作的是: enter image description here

编辑:我正在使用面向 8.4 的 Xcode-Beta 7

最佳答案

尝试

func animateLogo() {
logoView.layoutIfNeeded()
UIView.animateWithDuration(2.5, animations: {
self.logoViewVerticalConstraint.constant = 35 - (self.view.frame.size.height / 2);
self.logoView.alpha=1
self.logoView.layoutIfNeeded()
})
}

关于ios - UIView 动画不动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32171842/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com