【问题标题】:How to move image in circle swift如何快速移动圆圈中的图像
【发布时间】:2016-09-01 15:46:15
【问题描述】:

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

我需要什么:

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

我发现了如何做圆的路径,但其余的我不知道该怎么做。我是 iOS 开发的新手。

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

【问题讨论】:

    标签: ios swift core-graphics


    【解决方案1】:

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

    希望对你有帮助,问候

    【讨论】:

    • 您需要什么?你需要动画 90 然后?我认为你需要的是在你的所有观点中转圈圈
    • 我需要的第一个 img 将移动 90º 后 2 个 img 将移动其他 90º 和 3,4 个 img 相同
    • 在一个完美的圈子里?您还可以将所有子视图放在一个视图中并旋转?
    • 我只需要像我在上面那样移动调色板和卡车我会想我怎么能解决这个问题......但是有人认为我如何做这个动作将从左边开始,因为它从右边开始
    • 使用clockwise: false 而不是clockwise: true
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多