2016-09-28 10 views
1

を働いていない、私はそれが原因OBJで働いていない、なぜそれがうまく働いているC、私のコードを見てください。ここCABasicAnimationの迅速な私は、新たに迅速にOBJのCから移動してい

が私のコードであるか分かりません

func addAnimationOnLayer(layer: CALayer, position: CGPoint, duration: TimeInterval, delay: TimeInterval, fromPosition: CGPoint, toPostion: CGPoint, key: String) { 
     layer.setAffineTransform(CGAffineTransform(translationX: position.x, y: position.y)) 
     CATransaction.begin() 
     CATransaction.setCompletionBlock { 
      layer.setAffineTransform(CGAffineTransform(translationX: 0, y: 0)) 
     } 
     let theAnimation = CABasicAnimation(keyPath: "transform.translation") 
     theAnimation.isRemovedOnCompletion = false 
     theAnimation.timingFunction = CAMediaTimingFunction(name:kCAMediaTimingFunctionEaseInEaseOut) 
     theAnimation.fillMode = kCAFillModeForwards 
     theAnimation.duration = duration 
     theAnimation.beginTime = delay 
     theAnimation.fromValue = fromPosition 
     theAnimation.toValue = toPostion 

     layer.add(theAnimation, forKey: key) 
     CATransaction.commit() 
    } 

と私はCATransaction.flush()を呼び出すCATransaction.begin()試みを呼び出す前に、この

self.addAnimationOnLayer(layer: self.logoImage.layer, position: CGPoint(x: 0, y:100), duration: 0.8, delay: 0.1, fromPosition: CGPoint(x: 0,y: 100), toPostion: CGPoint(x: 0,y: 0), key: "logoStartAnimation") 

答えて

1

で関数を呼び出します。

あなたのコードは、次にようになります。

func addAnimationOnLayer(layer: CALayer, position: CGPoint, duration: TimeInterval, delay: TimeInterval, fromPosition: CGPoint, toPostion: CGPoint, key: String) { 
    layer.setAffineTransform(CGAffineTransform(translationX: position.x, y: position.y)) 
    CATransaction.flush() 
    CATransaction.begin() 
    CATransaction.setCompletionBlock { 
     layer.setAffineTransform(CGAffineTransform(translationX: 0, y: 0)) 
    } 
    let theAnimation = CABasicAnimation(keyPath: "transform.translation") 
    theAnimation.isRemovedOnCompletion = false 
    theAnimation.timingFunction = CAMediaTimingFunction(name:kCAMediaTimingFunctionEaseInEaseOut) 
    theAnimation.fillMode = kCAFillModeForwards 
    theAnimation.duration = duration 
    theAnimation.beginTime = delay 
    theAnimation.fromValue = fromPosition 
    theAnimation.toValue = toPostion 

    layer.add(theAnimation, forKey: key) 
    CATransaction.commit() 
} 

がいることを試してみて、私に知らせて、私はアニメーションが原因残さ前のアニメーションのビットで起きていないと前に問題がありました。

+0

あなたの助けてくれてありがとう、アニメーションが壊れているように見えます(早送り/スキップ)。 私はCATransactionのアニメーションを削除しようとしてもまだ動作しません – Renandus