我在下面的代码中使用了UIView
animateWithDuration
来增加shapeLayer.frame.size.height
,但无论持续时间如何,它都会快速动画。我发现一些帖子推荐使用一些延迟时间,我已经这样做了,但它仍然非常快地动画,并忽略我设置的5秒持续时间。
private let minimalHeight: CGFloat = 50.0
private let shapeLayer = CAShapeLayer()
override func loadView() {
super.loadView()
shapeLayer.frame = CGRect(x: 0.0, y: 0.0, width: view.bounds.width, height: minimalHeight)
shapeLayer.backgroundColor = UIColor(red: 57/255.0, green: 67/255.0, blue: 89/255.0, alpha: 1.0).CGColor
view.layer.addSublayer(shapeLayer)
}
func delay(delay:Double, closure:()->()) {
dispatch_after(
dispatch_time(
DISPATCH_TIME_NOW,
Int64(delay * Double(NSEC_PER_SEC))
),
dispatch_get_main_queue(), closure)
}
override func viewDidAppear(animated: Bool) {
delay(3) {
UIView.animateWithDuration(5.0) {
self.shapeLayer.frame.size.height += 400.0
}
}
如何使动画在5秒内完成?