斯威夫特:移动UIImage的部分沿路径 [英] Swift: Move UIImage partly along path

查看:122
本文介绍了斯威夫特:移动UIImage的部分沿路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用这code键移动沿曲线一个UIImage:

I am using this code to move a UIImage along a curve:

    // 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")

不过,有两个问题仍然是:

Nevertheless, two issues remain:


  • 我想(根据当前时间与日出/日落)移动图像只沿路径部分 - 如何才能做到这一点

  • 图像跳转到其初始位置。在动画停止后 - 我怎样才能避免这种

干杯

推荐答案

要避免跳转到原来的位置添加:

To avoid jump to its original position add:

animation.fillMode = kCAFillModeForwards
animation.removedOnCompletion = false

这篇关于斯威夫特:移动UIImage的部分沿路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆