gpt4 book ai didi

ios - Swift animateWithDuration 立即完成

转载 作者:行者123 更新时间:2023-11-28 11:19:18 27 4
gpt4 key购买 nike

这是我的代码我立即得到打印输出。我想在此期间更改我的 uiview 的背景颜色。

func animate() {

UIView.animateWithDuration(3.0, delay: 0.0, options:

UIViewAnimationOptions.CurveLinear, animations: {

//self.grid.backgroundColor = UIColor.redColor()
println("1")

UIView.animateWithDuration(1.0, delay: 1.0, options: UIViewAnimationOptions.CurveLinear, animations: {

//self.grid.backgroundColor = UIColor.clearColor()
println("2")

},
completion: {
(finished: Bool) - > Void in

println("3")

})
}, completion: {
(finished: Bool) - > Void in

println("4")

})
}

最佳答案

您尝试设置动画的对象不可设置动画。通过检查您的代码,我了解到您正在尝试使 View 透明。

您可以通过使 View 的 alpha 为零来实现此目的。 (Alpha 是可动画的)。

与红色相同。尝试改用图层背景色

另外请记住,animationWithDuration 不会延迟赋值,值会立即赋值

UIView.animateWithDuration(3.0, delay: 0.0, options:UIViewAnimationOptions.CurveLinear, animations: {

self.grid.layer.backgroundColor = UIColor.redColor().CGColor


UIView.animateWithDuration(1.0, delay: 1.0, options: UIViewAnimationOptions.CurveLinear, animations: {

self.grid.alpha = 0


},
completion: {(finished: Bool) - > Void in})
}, completion: {(finished: Bool) - > Void in})}

关于ios - Swift animateWithDuration 立即完成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29658225/

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