【发布时间】:2015-08-11 18:30:06
【问题描述】:
我正在使用此代码沿曲线移动 UIImage:
// paint curve for sun
let path = UIBezierPath()
let imageSunName = "small_sun.png"
let imageSun = UIImage(named: imageSunName)
let imageView = UIImageView(image: imageSun!)
imageView.frame = CGRect(x: xStart, y: yStart, width: 24, height: 24)
self.view.addSubview(imageView)
path.moveToPoint(CGPoint(x: xStart,y: yStart))
path.addQuadCurveToPoint(CGPoint(x: xEnd, y: yEnd), controlPoint: CGPoint(x: xMiddleTop, y: yMiddleTop))
let animation = CAKeyframeAnimation(keyPath: "position")
animation.path = path.CGPath
animation.repeatCount = 0
animation.duration = 5.0
imageView.layer.addAnimation(animation, forKey: "animate position along path")
不过,还有两个问题:
- 我只想沿路径移动图像的一部分(根据当前时间与日出/日落时间) - 怎么做?
- 动画停止后图像跳转到其原始位置 - 如何避免这种情况?
干杯
【问题讨论】: