如何快速移动图像 [英] How to move image in circle swift

查看:64
本文介绍了如何快速移动图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以向我解释如何创建圆的路径并在其周围移动图像。



我需要什么:

  let circlePath = UIBezierPath(arcCenter:CGPoint(x:100,y:100),radius:CGFloat(20),startAngle:CGFloat(0),endAngle:CGFloat(M_PI * 2),顺时针:正确)

我发现圆的路径,但是其余的我都不知道去做。我是iOS开发的新手。



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

解决方案

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

  import UIKit 

类ViewController:UIViewController {
@IBOutlet弱var objectToMove :UIView!

覆盖func viewDidLoad(){
super.viewDidLoad()
//加载视图后,通常从笔尖进行其他任何设置。
}

覆盖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)),半径:CGFloat(100),startAngle:CGFloat(0),endAngle:CGFloat(M_PI * 2),顺时针: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)
}

覆盖func didReceiveMemoryWarning(){
super.didReceiveMemoryWarning()
// d浪费任何可以重新创建的资源。
}


}

我希望这样可以帮助您,

Can anybody explain to me how I can create the path of circle and move an image around it.

What I need:

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

I discovered how do the path of circle, but the rest I don't know to do. I'm new to iOS development.

And, I need this action begin when I open the page.

解决方案

Check this code, the objectToMove is an UIView from storyBoard to test, here I am using your path code but I had added more radius

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.
    }


}

I hope this helps you, Regards

这篇关于如何快速移动图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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