9 Replies Latest reply: Sep 19, 2008 10:06 AM by Felixk
kingsoul8 Level 1 Level 1
I have a UIImageView that I am animating with the CGAffineTransformMakeRotation but I can't quite figure out how to get it to do a full 360 degree rotation. When I double 3.14 it no longer rotates because it's already there. How do I get past the first 180 degrees?

Any help, direction, links or code is much appreciated.


iMac 2.16 GHz Intel Core 2 Duo, Mac OS X (10.5.4)
  • kingsoul8 Level 1 Level 1
    I am trying to have an image run on a continuous rotating (360 degree) loop like the second hand of clock. Maybe there is an better or easier way of doing this other than CGAffineTransformMakeRotation. I have looked at the GLSprite code and that is a little beyond me right now.
  • Felixk Level 1 Level 1
    Have you figured this out?

    I'm trying to do the same thing, and I can't get the rotation passed 180 degrees.

  • just.do.it Level 3 Level 3
    Have you tried negativ values? The first half goes from 0 - Pi, the second half from -Pi to 0. This should form a 360 degree turn.
  • Felixk Level 1 Level 1
    Hey thanks for the reply..Just gave it a try,and it didn't help. Here is my code:

    CABasicAnimation *rotateAnimation = |CABasicAnimation animationWithKeyPath:@"transform"|;
    rotateAnimation.duration = 1;
    rotateAnimation.repeatCount = 1;
    rotateAnimation.autoreverses = NO;
    rotateAnimation.toValue = |NSValue valueWithCATransform3D:CATransform3DRotate(touchedLayer.transform, DegreesToRadians(180), 1.0 ,0.0 ,0.0)|;

    CABasicAnimation *rotateBackAnimation = |CABasicAnimation animationWithKeyPath:@"transform2"|;
    rotateBackAnimation.duration = 1;
    rotateBackAnimation.repeatCount = 1;
    rotateBackAnimation.autoreverses = NO;
    rotateBackAnimation.toValue = |NSValue valueWithCATransform3D:CATransform3DRotate(touchedLayer.transform, DegreesToRadians(-180), 1.0 ,0.0 ,0.0)|;

    |touchedLayer addAnimation:rotateAnimation forKey:@"rotate"|;
    |touchedLayer addAnimation:rotateBackAnimation forKey:@"rotateback"|;

    Any ideas?
  • Arca Level 1 Level 1
    A 360 degree transformation is no transformation, but you cn rotate something a full 360 degrees by applying a smaller rotation multiple times. I would compute the transformation for a 90degree rotation and apply that 4 times in the time you wanted to apply the 360 rotation once.
  • Felixk Level 1 Level 1
    I tried that... I set rotateAnimation.repeatCount = 4; and the angle to 90 degrees..

    Basically it just rotates my view 90 degrees 4 times from the same position. Meaning the transformation isn't combining, but rather it rotates 90 degrees resets back to 0 and does it again 3 more times.

    Any idea how to "combine" transformations?

  • doniguan Level 1 Level 1
    I dont have any experience here so i could be blowing smoke- but i think you would have to save the matrix after every transformation- and combine it with the current matrix when doing a new transformation.
  • Felixk Level 1 Level 1
    Yea you are probably right...the CGAffineTransformMakeRotation actually returns a matrix...then i can use

    CGAffineTransform CGAffineTransformRotate (
    CGAffineTransform t,
    CGFloat angle

    To transform the original Matrix.

    I will give it a shot and report back.
  • Felixk Level 1 Level 1
    That works..thanks for the help.