我的 ViewController viewDidLoad 函数中的 UIView.animateWithDuration 调用没有动画。立即调用完成 block 。 println 输出显示“完成为真”。 viewDidLoad 函数是否放错了我的启动动画?非常感谢任何提示。
class ViewController: UIViewController {
@IBOutlet var beatIndicator:UIView?
override func viewDidLoad() {
super.viewDidLoad()
if let led = beatIndicator? {
led.alpha = 1.0
led.frame = CGRectMake(20, 20, 30, 30)
led.layer.cornerRadius = 15
UIView.animateWithDuration(3.0, animations:{
led.alpha = 0.5
led.frame = CGRectMake(25, 25, 20, 20)
led.layer.cornerRadius = 10
}, completion:{(value: Bool) in
println("completion \(value)")
})
}
// ...
}
}
最佳答案
你试过把它放在 ViewDidAppear 中吗?
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
if let led = beatIndicator {
led.alpha = 1.0
led.frame = CGRect(x: 20, y: 20, width: 30, height: 30)
led.layer.cornerRadius = 15
UIView.animate(withDuration: 3.0, animations:{
led.alpha = 0.5
led.frame = CGRect(x: 25, y: 25, width: 20, height: 20)
led.layer.cornerRadius = 10
}, completion:{(value: Bool) in
print("completion \(value)")
})
}
// ...
}
关于swift - UIView.animateWithDuration 没有动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26118141/