gpt4 book ai didi

ios - Swift:使图像在 UIBezierPath(overInRect) 中连续循环

转载 作者:行者123 更新时间:2023-11-28 09:06:10 25 4
gpt4 key购买 nike

我有一个蓝色圆圈的图像,我想让它在椭圆路径中连续循环。我首先创建了一个圆形路径,它成功了,但是创建一个椭圆形路径循环了这个圆圈,但在它再次循环之前暂时停止了。有什么我想念的,可以毫不犹豫地制作椭圆形路径循环。这是两个循环的代码。

    func performRotation(){
let path = UIBezierPath(ovalInRect: CGRectMake(50, 50, 220, 100))
let anim = CAKeyframeAnimation(keyPath: "position")

anim.path = path.CGPath
anim.rotationMode = kCAAnimationLinear
anim.repeatCount = Float.infinity
anim.duration = 5.0

//@IBOutlet weak var ball: UIImageView!
ball.layer.addAnimation(anim, forKey: "animate position along path")

//this is the circle path that loops without the stutter

// let ovalStartAngle = CGFloat(90.01 * M_PI/180)
// let ovalEndAngle = CGFloat(90 * M_PI/180)
// let ovalRect = CGRectMake(97.5, 58.5, 125, 125)
//let path = UIBezierPath()
//path.moveToPoint(CGPoint(x: 200, y: 150))
//path.addArcWithCenter(CGPointMake(CGRectGetMidX(ovalRect), CGRectGetMidY(ovalRect)),
//radius: CGRectGetWidth(ovalRect) / 2,
//startAngle: ovalStartAngle,
//endAngle: ovalEndAngle, clockwise: true)

//let anim = CAKeyframeAnimation(keyPath: "position")
//anim.path = path.CGPath
//anim.rotationMode = kCAAnimationLinear
//anim.repeatCount = Float.infinity
//anim.duration = 5.0
//ball.layer.addAnimation(anim, forKey: "animate position along path")

}

最佳答案

尝试设置计算模式,而不是设置旋转模式,

anim.calculationMode = kCAAnimationPaced

关于ios - Swift:使图像在 UIBezierPath(overInRect) 中连续循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30686852/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com