2016-09-01 6 views
0

どのように円のパスを作成し、その周りの画像を移動することができます誰に説明することができます。私は必要なもの円のスイフトで画像を移動するには

enter image description here

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

私はサークルのパスを行う方法を発見し、残りは、私は何をするかわかりません。私はiOS開発の新人です。

そして、私はこのページを開くときにこのアクションを開始する必要があります。

答えて

3

チェックこのコードは、objectToMoveは、ここで私はあなたのパスコードを使用していますテストするための絵コンテから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. 
    } 


} 

、よろしく

+0

その作業を追加しましたありがとう、しかし、私は90度でこれを止めるのですか? –

+0

何が必要ですか?あなたは90アニメーションをする必要がありますか?私はあなたが必要と思うすべてのあなたの意見を円で移動する必要があると思う –

+0

私はfisrtを必要とするimg wiil移動90°後2 imgは他の90°と3,4 img同じを移動します –