如何在圆圈中快速移动图像

时间:2016-09-01 15:46:15

标签: ios swift core-graphics

任何人都可以向我解释如何创建圆形路径并围绕它移动图像。

我需要什么: enter image description here

@using Kendo.Mvc.UI

@(Html.Kendo().Upload()
        .Name("files")
        .Async(a => a
            .Save("SaveAttachments", "Home")
            .Remove("RemoveAttachments", "Home")
            .AutoUpload(true)
        )
        .Events(e => e.Success("onUploadSuccess"))
)
我发现圈子的路径怎么样,但其余的我不知道要做什么。我是iOS开发的新手。

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

1 个答案:

答案 0 :(得分:3)

检查这段代码,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.
    }


}

我希望这可以帮助你,问候