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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:38:41+00:00 2026-05-13T16:38:41+00:00

im trying to do an animation with an uiimageview . in this view is

  • 0

im trying to do an animation with an uiimageview.
in this view is an image with an arrow, that i want to rotate about 45 degrees back and forward very smoothly like an pendular or an old clock.
something like this, just smooth and with my image: http://bit.ly/cArvNw (found this with google 😉 )

my current setup looks like this:

    UIImageView* rotatingImage = [[UIImageView alloc] initWithFrame:CGRectMake(10.0, 10.0, 200.0, 200.0)];
    [rotatingImage setImage:[UIImage imageNamed:@"wind.png"]];

    CALayer *layer = rotatingImage.layer;
    CAKeyframeAnimation *animation;
    animation = [CAKeyframeAnimation animationWithKeyPath:@"transform.rotation.z"];
    animation.duration = 0.5f;
    animation.cumulative = YES;
    animation.repeatCount = 100;
    animation.values = [NSArray arrayWithObjects:           // i.e., Rotation values for the 3 keyframes, in RADIANS
                        [NSNumber numberWithFloat:[self degreesToRadians:45.0]], 
                        [NSNumber numberWithFloat:[self degreesToRadians:-45.0]], nil]; 
    animation.keyTimes = [NSArray arrayWithObjects:     // Relative timing values for the 3 keyframes
                          [NSNumber numberWithFloat:0], 
                          [NSNumber numberWithFloat:.5], nil]; 
    animation.timingFunctions = [NSArray arrayWithObjects:
                                 [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn],        // from keyframe 1 to keyframe 2
                                 [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut], nil]; // from keyframe 2 to keyframe 3
    animation.removedOnCompletion = NO;
    animation.fillMode = kCAFillModeForwards;

    [layer addAnimation:animation forKey:nil];

    [self addSubview:rotatingImage];

this is really a pain, add 45 degrees, then 45 degrees backward with “-45” doesnt work.
im very new to core animation and dont know how to setup my code, to get my wanted animation.

can anybody help please?

  • 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-13T16:38:41+00:00Added an answer on May 13, 2026 at 4:38 pm

    Note: This method does not use Core Animation, but it’s very simple and probably uses less resources.

    First, make the UIImageView twice as tall, thereby making the center of rotation equal to the center of the image.

    Then, define these in the @interface of the header file (of, say, your UIViewController):

    BOOL goingCW; // going clockwise = YES, going counterclockwise = NO
    CGFloat angle; // angle by which to change the image's rotation value
    

    Then put this in an init method that runs once:

    goingCW = YES; // change this to NO to make it start rotating CCW instead
    angle = 0;
    
    [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(update) userInfo:nil repeats:YES];
    

    Then define update, given that arrow is the UIImageView instance:

    - (void)update {
        if (goingCW) {
            if (angle > M_PI / 4) goingCW = NO; // M_PI / 4 is equal to 45 degrees
            angle += M_PI / 60; // increase 60 to slow down the rotation, etc.
        } else {
            if (angle < -M_PI / 4) goingCW = YES; // -M_PI / 4 is equal to -45 degrees
            angle -= M_PI / 60; // increase 60 to slow down the rotation, etc.
        }
    
        // rotate the UIImageView appropriately
        arrow.transform = CGAffineTransformMakeRotation(angle);
    }
    

    This also assumes that you are starting in the facing-down position.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to do a multistage animation, so that a UIImageView (1) fades in,
I'm trying to create an animated UIImageView with certain image constraints. I want the
I am trying to draw an animation. To do so I have extended View
I'm trying to create an animation that would look like 2 french doors (or
I'm trying to animate an image to rotate left and right when selected, basically
I'm trying to rotate a UIImageView within a circular mask (which is set with
I am trying to do animation. At some point I want to execute a
This problem should be simple enough, i am trying to learn animation using javascript
I'm trying to make a UIImageView loaded with an array for an animation appear
I'm trying to create a floating effect using this code over a UIImageView: [UIView

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.