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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:44:41+00:00 2026-05-28T17:44:41+00:00

I want to turn an image 190 degrees when pressing a button. That works

  • 0

I want to turn an image 190 degrees when pressing a button. That works but when i press the button again the animation needs to start where it last ended, instead of starting from 0. So everytime i press the button, the animation need to turn a 190 degrees.

It is starting at 0 everytime becouse my fromValue is set to 0.

Does someone know how i can make the fromValue start where my image ends. My code is below here.

- (IBAction)buttonPressed
{ 
    CABasicAnimation *imageRotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];

    imageRotation.fromValue = [NSNumber numberWithFloat:0];
    imageRotation.toValue = [NSNumber numberWithFloat:((190*M_PI)/ -180)];

    imageRotation.duration = 1.5;
    imageRotation.repeatCount = 1;

    imageRotation.removedOnCompletion = NO;
    imageRotation.autoreverses=NO;
    imageRotation.fillMode = kCAFillModeForwards;

    [image.layer addAnimation:imageRotation forKey:@"imageRotation"];
}
  • 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-28T17:44:43+00:00Added an answer on May 28, 2026 at 5:44 pm

    Thanks for your answer, but here is how i did it. Hope people can use this 😀

    My .h file looks like this:

    #import <UIKit/UIKit.h>
    #import <QuartzCore/QuartzCore.h>
    
    @interface testViewController : UIViewController {
       IBOutlet UIImageView *image;
       NSObject *lastValue;
    }
    
    - (IBAction)buttonPressed;
    
    @property(nonatomic, retain) IBOutlet NSObject *lastValue;
    
    @end
    

    My .m file looks like this:

    @synthesize lastValue;
    
    - (void)viewAnimation0 
    {
       CABasicAnimation *imageRotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
    
       imageRotation.fromValue = lastValue;
       imageRotation.toValue = [NSNumber numberWithFloat:((30*M_PI)/ -180)];
       lastValue = imageRotation.toValue;
    
       imageRotation.duration = 1.5;
       imageRotation.repeatCount = 1;
    
       imageRotation.removedOnCompletion = NO;
       imageRotation.autoreverses=NO;
       imageRotation.fillMode = kCAFillModeForwards;
    
       [image.layer addAnimation:imageRotation forKey:@"imageRotation"];
    }
    
    - (void)viewAnimation1 
    {
       CABasicAnimation *imageRotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
    
       imageRotation.fromValue = lastValue;
       imageRotation.toValue = [NSNumber numberWithFloat:((60*M_PI)/ -180)];
       lastValue = imageRotation.toValue;
    
       imageRotation.duration = 1.5;
       imageRotation.repeatCount = 1;
    
       imageRotation.removedOnCompletion = NO;
       imageRotation.autoreverses=NO;
       imageRotation.fillMode = kCAFillModeForwards;
    
       [image.layer addAnimation:imageRotation forKey:@"imageRotation"];
    }
    
    - (void)viewAnimation2 
    {
       CABasicAnimation *imageRotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
    
       imageRotation.fromValue = lastValue;
       imageRotation.toValue = [NSNumber numberWithFloat:((90*M_PI)/ -180)];
       lastValue = imageRotation.toValue;
    
       imageRotation.duration = 1.5;
       imageRotation.repeatCount = 1;
    
       imageRotation.removedOnCompletion = NO;
       imageRotation.autoreverses=NO;
       imageRotation.fillMode = kCAFillModeForwards;
    
       [image.layer addAnimation:imageRotation forKey:@"imageRotation"];
    }
    
    - (IBAction)buttonPressed 
    {
       static int counter = 0;
       switch (++counter) {
    
        case 1:
            [self viewAnimation1];
            break;
    
        case 2:
            [self viewAnimation2];
            break;
    
        default:
            [self viewAnimation0];
            counter = 0;
            break;
       }
       //    animateButton.enabled = NO;
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How to apply curl animation on Image.( i want animation like Books page turn
I have a set of points that i want to turn into a closed
I created a console application, but I want to turn it into a windows
How do I turn a gradient image to a footer? I want to turn
I want to show different images in a DIV, the turn of an image
I want to make a program that takes an image as input and outputs
I have this image: What I want to do is turn it into a
I want to replace color of an image. For example turn all blue colors
I don't want to turn off resizing completely, but the resize handles on textareas
I know that I can do the following if I want to turn an

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.