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 8809609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:55:09+00:00 2026-06-14T02:55:09+00:00

In my iphone app I have a UIButton that I rotate 180 degrees into

  • 0

In my iphone app I have a UIButton that I rotate 180 degrees into view when another UIButton is pressed, then when clicked again the button rotates a further 180 degrees back to where it started.

This all works fine the very first time the complete 360 degree process occurs, but if I try to start from the start again it snaps 180 degrees then tries to rotate it from that point. Can anyone point me in the right direction? Here’s my code so far…

showAnimation= [CAKeyframeAnimation animationWithKeyPath:@"transform.rotation"];
                    showAnimation.duration = self.showAnimationDuration;
                    showAnimation.repeatCount = 1;
                    showAnimation.fillMode = kCAFillModeForwards;
                    showAnimation.removedOnCompletion = NO;
                    showAnimation.cumulative = YES;
                    showAnimation.delegate = self;

float currentAngle =[[[rotateMe.layer presentationLayer] valueForKeyPath:@"transform.rotation.z"] floatValue];

//Rotate 180 degrees from current rotation
showAnimation.values = [NSArray arrayWithObjects:       
                        [NSNumber numberWithFloat:currentAngle],
                        [NSNumber numberWithFloat:currentAngle + (0.5 * M_PI)],
                        [NSNumber numberWithFloat:currentAngle + M_PI], nil];

[rotateMe.layer addAnimation:showAnimation forKey:@"show"];

On completion of the animation I then update the rotateMe.transform rotation to the layer’s rotation so that it becomes usable.

- (void)animationDidStop:(CAKeyframeAnimation *)anim finished:(BOOL)flag
{
    float currentAngle =[[[self.layer presentationLayer] valueForKeyPath:@"transform.rotation.z"] floatValue];

    NSLog(@"End: %f", currentAngle);
    rotateMe.transform = CGAffineTransformMakeRotation(0);
}

I have achieved the fully working effect with

    [UIView animateWithDuration:1.0f]
        animations:^{
            CGAffineTransform transform = CGAffineTransformRotate(rotateMe.transform, DEGREES_TO_RADIANS(179.999f));
            rotateMe.transform = transform;
        }
     ];

But I’d like to make the animation more complex, hence the CAKeyframeAnimation.

  • 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-06-14T02:55:10+00:00Added an answer on June 14, 2026 at 2:55 am

    You could configure the animation to be additive and animate from 0 to 180 degrees if you need all the key frames. If you don’t need the different key frames the you can simply do it with a basic animation and the byValue property. The next time the animation is added it rotate 180 more degrees than whatever rotation is on the view.

    If you are setting the actual value in the delegate callback then there is no need for fill mode and not removing the animation on completion.

    CABasicAnimation *showAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
    showAnimation.byValue = M_PI;
    showAnimation.duration = self.showAnimationDuration;
    showAnimation.delegate = self;
    
    [rotateMe.layer addAnimation:showAnimation forKey:@"show"];
    

    or using a key frame animation (as explained above: make it additive and animate from 0 to 180 degrees).

    CAKeyframeAnimation *showAnimation = [CAKeyframeAnimation animationWithKeyPath:@"transform.rotation.z"];
    showAnimation.additive = YES; // Make the values relative to the current value
    showAnimation.values = @[0, /*all your intermediate values here... ,*/ M_PI];
    showAnimation.duration = self.showAnimationDuration;
    showAnimation.delegate = self;
    
    [rotateMe.layer addAnimation:showAnimation forKey:@"show"];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a UIButton in my iPhone app that, when clicked, plays a movie.
I have a regular old iPhone app that has a main view controller that
I have an iphone app that has a root view with a button that
I have an iPhone app with a main view that has a UILabel and
In my iPhone app I have a table view where I add a tick
I have a UIWebView in my iPhone app that have a web page with
I'm creating an iPhone app that will have a preloaded set of locations with
I currently have an iPhone app that lets the users take video, upload it
I have an iPhone app that I've built for the app store. Before I
I have an iPhone app problem that's been bugging me for a few days

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.