loo*_*sta 2 animatewithduration swift ios8 xcode6.0.1
我的ViewController viewDidLoad函数中的UIView.animateWithDuration调用没有动画.立即调用完成块.println输出显示'completion true'.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)")
})
}
// ...
}
}
Run Code Online (Sandbox Code Playgroud)
你试过把它放在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)")
})
}
// ...
}
Run Code Online (Sandbox Code Playgroud)