title: Rotating CALayer more than 180 degrees using transform
body: <p>I am trying to rotate a CALayer by a little less than 360 degrees but instead the transform rotates it in opposite direction (that is smaller of the two angles). How can I achieve this rotation given I am also applying a translation transform on the layer? Also, I want to be able to control the direction of rotation. It seems CAAnimation wouldn't heed and take the shorter angle of the transform for rotation. It seems these two problems are perhaps related. Here's how part of my swift code looks:</p>
  
  <pre><code>func addAnimation() {
      var animation : CABasicAnimation = CABasicAnimation(keyPath: "transform")
  
      animation.delegate = self
  
      let translateDistY = CGRectGetMidY(self.view.bounds) - CGRectGetMidY(self.displayLayer.bounds)
      let rotationAngle = (CGFloat(M_PI*2.0) - 0.1)
  
      var transform : CATransform3D = CATransform3DMakeTranslation(0, translateDistY, 0)
      transform = CATransform3DRotate(transform, rotationAngle, 0, 0, 1)
  
      animation.fromValue = NSValue(CATransform3D: CATransform3DIdentity)
      animation.toValue = NSValue(CATransform3D: transform)
  
      animation.duration = 1.3
      animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseOut)
  
      let animStruct = animationStruct(animLayer: self.displayLayer, animation: animation, layerTransform: transform)
  
      self.animationSequence.append(animStruct)
  }
  
  func doAnimation() {
      if  animationSequence.count &gt; 0 {
          let animStruct = animationSequence.removeAtIndex(0)
          animStruct.animLayer.transform = animStruct.layerTransform
          animStruct.animLayer.addAnimation(animStruct.animation, forKey: nil)
      }
  }
  
  override func animationDidStop(anim: CAAnimation!, finished flag: Bool) {
      self.doAnimation()
  }
  </code></pre>