Swift:沿路径部分移动UIImage

前端之家收集整理的这篇文章主要介绍了Swift:沿路径部分移动UIImage前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用此代码沿着曲线移动UI Image
// 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")

尽管如此,还有两个问题:

>我想仅沿路径部分移动图像(根据当前时间对日出/日落) – 如何做到这一点?
>动画停止后图像跳转到原点位置 – 我该怎样避免这种情况?

干杯

为了避免跳到原来的位置,请添加
animation.fillMode = kCAFillModeForwards
animation.removedOnCompletion = false
原文链接:/swift/318688.html

猜你在找的Swift相关文章