Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6534533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:15:45+00:00 2026-05-25T10:15:45+00:00

This one has been driving me nuts… Considering plane is a CALayer, I rotate

  • 0

This one has been driving me nuts…

Considering “plane” is a CALayer, I rotate it in the X axis:

plane.transform = CATransform3DMakeRotation(180 * M_PI / 180.0f, 1.0f, 0.0f, 0.0f);

And this makes it rotate clockwise, which is perfect.

Now, at some point in time, I want it to return to 0 degrees, so I use:

plane.transform = CATransform3DMakeRotation(0 * M_PI / 180.0f, 1.0f, 0.0f, 0.0f);

The thing is… it does it anti-clockwise, which is not what I want 🙁

I’m guessing it uses the shortest rotation path, but even if I tell it to go to 360 degrees instead, when it’s done and I tell it to restart the animation, it starts from 360 to go to 180, and it goes backwards instead of the right direction.

Is there a way to workaround that?

What I’d do in Actionscript would be:

if (plane.rotationX == 360) plane.rotationX = 0;

And it’d resume nicely, but if I do that using CATransform3DMakeRotation both transformations collide, because of the animation (I think) and it gets messed up.

Any help would be much appreciated!

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T10:15:46+00:00Added an answer on May 25, 2026 at 10:15 am

    This question came up when I was searching to solve a similar issue. I wanted to rotate an image 180 degrees and then wanted to keeping going around for a full somersault. iOS wanted to take the shortest route back. The answer here didn’t help me too much. I ended up looking up some stuff on keyPath animations and that solved my issue. Below is an example of the approach.

    For the particular issue raised in the question, you’d need two different sets of keyFrameValues, one for the initial rotation and another for the second. But by putting in an intermediate value you can get the desired effect, i.e. take the longer path or force the choice of equally long paths, if that’s what you want. I’ve left some variant code in comments, as they may help folk not familiar with CAKeyFrameAnimation follow the code / understand the range of options.

    - (void) somersault;
    {
    
        CALayer* layer = [self layer];
        NSMutableArray* keyFrameValues = [NSMutableArray array];
        [keyFrameValues addObject:[NSNumber numberWithFloat:0.0]];
        //[values addObject:[NSNumber numberWithFloat:M_PI*0.5]];
        [keyFrameValues addObject:[NSNumber numberWithFloat:M_PI]];
        [keyFrameValues addObject:[NSNumber numberWithFloat:M_PI*1.5]];
        [keyFrameValues addObject:[NSNumber numberWithFloat:M_PI*2.0]];
    
        CAKeyframeAnimation* animation = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
        [animation setValues:keyFrameValues];
        [animation setValueFunction:[CAValueFunction functionWithName: kCAValueFunctionRotateX]];// kCAValueFunctionRotateZ]];
    
        [animation setDuration:0.9];
        //[animation setTimingFunction: [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
    
        [layer addAnimation:animation forKey:nil];
    
        return;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This one has been driving me nuts for a few days now and I've
This has been driving me nuts, I'm posting here after a lot of looking
This problem has been driving me nuts all day and there has to be
This one has been driving me crazy today. Since upgrading to Grails 1.2 and
This has been driving me nuts for the past hour. I have two computers,
This one has been bugging me for a while now. Is there a way
This one has been stumping me for a while. But I'm no expert. This
This has been one of the biggest obstacles in teaching new people ColdFusion. When
This could be considered a duplicate question, as a similar one has already been
This is driving me nuts - I have been round and round in circles,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.