繁体   English   中英

如何快速移动图像

[英]How to move image in circle swift

谁能向我解释如何创建圆的路径并在其周围移动图像。

我需要的: 在此处输入图片说明

let circlePath = UIBezierPath(arcCenter: CGPoint(x: 100,y: 100), radius:  CGFloat(20), startAngle: CGFloat(0), endAngle:CGFloat(M_PI * 2), clockwise: true)

我发现了绕圈的路径,但是其余的我都不知道。 我是iOS开发的新手。

而且,我需要在打开页面时开始执行此操作。

检查此代码,objectToMove是一个来自storyBoard的UIView进行测试,这里我使用的是您的路径代码,但是我添加了更多的半径

import UIKit

class ViewController: UIViewController {
    @IBOutlet weak var objectToMove: UIView!

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }

    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)

        let orbit = CAKeyframeAnimation(keyPath: "position")
        var affineTransform = CGAffineTransformMakeRotation(0.0)
        affineTransform = CGAffineTransformRotate(affineTransform, CGFloat(M_PI))
        let circlePath = UIBezierPath(arcCenter: CGPoint(x: 100 - (100/2),y: 100 - (100/2)), radius:  CGFloat(100), startAngle: CGFloat(0), endAngle:CGFloat(M_PI * 2), clockwise: true)
        orbit.path = circlePath.CGPath
        orbit.duration = 4
        orbit.additive = true
        orbit.repeatCount = 100
        orbit.calculationMode = kCAAnimationPaced
        orbit.rotationMode = kCAAnimationRotateAuto

        objectToMove.layer .addAnimation(orbit, forKey: "orbit")
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}

希望对您有帮助

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM