加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Swift:沿路径部分移动UIImage

发布时间:2020-12-14 05:39:48 所属栏目:百科 来源:网络整理
导读:我正在使用此代码沿着曲线移动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
我正在使用此代码沿着曲线移动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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读