关键函数如下
func expand() {
var expandAnimation: CABasicAnimation = CABasicAnimation(keyPath: "path")
expandAnimation.fromValue = ovalPathSmall.CGPath
expandAnimation.toValue = ovalPathLarge.CGPath
expandAnimation.duration = animationDuration
expandAnimation.fillMode = kCAFillModeForwards
expandAnimation.removedOnCompletion = false
addAnimation(expandAnimation, forKey: nil)
}
关键代码解释:ovalPathSmall和ovalPathLarge如下:
var ovalPathSmall: UIBezierPath {
return UIBezierPath(ovalInRect: CGRect(x: 50.0, y: 50.0, width: 0.0, height: 0.0))
}
var ovalPathLarge: UIBezierPath {
return UIBezierPath(ovalInRect: CGRect(x: 2.5, y: 2.5, width: 95.0, height: 95.0))
}
ovalPathSmall其实画的是一个点,ovalPathLarge才是变大后的这个原(直径95),圆心其实就位于ovalPathSmall所画的这个点上
expandAnimation.fillMode = kCAFillModeForwards
expandAnimation.removedOnCompletion = false
确保动画完成以后确保圆为变化后的大圆图形。
简单来说,动画就是给定变化前后的图形,变化交给系统来实现。
网友评论