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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:45:20+00:00 2026-05-11T18:45:20+00:00

I want to wobble an image back and forth in my application similar to

  • 0

I want to wobble an image back and forth in my application similar to how the iPhone icons wobble when you press down on it. What’s the best way to do that?

This is my first foray into animations that’s not using an animated GIF. I think the idea is to slightly rotate the image back and forth to create the wobbling effect. I’ve looked at using CABasicAnimation and CAKeyframeAnimation. CABasicAnimation creates a jitter every time it repeats because it jumps to the from position and doesn’t interpolate back. CAKeyframeAnimation seems like the solution except that I can’t get it to work. I must be missing something. Here’s my code using the CAKeyframeAnimation (which doesn’t work):

    NSString *keypath = @"wobbleImage";
CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:keypath];
animation.duration = 1.0f;
animation.delegate = self;
animation.repeatCount = 5;

CGFloat wobbleAngle = 0.0872664626f;
NSValue *initial = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(0.0f, 0.0f, 0.0f, 1.0f)];
NSValue *middle = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(wobbleAngle, 0.0f, 0.0f, 1.0f)];
NSValue *final = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(-wobbleAngle, 0.0f, 0.0f, 1.0f)];
animation.values = [NSArray arrayWithObjects:initial, middle, final, nil];

[imageView.layer addAnimation:animation forKey:keypath];

Or there could be a totally simpler solution that I’m just missing. Appreciate any pointers. 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-11T18:45:20+00:00Added an answer on May 11, 2026 at 6:45 pm

    Simple way to do it:

    #define RADIANS(degrees) (((degrees) * M_PI) / 180.0)
    
    CGAffineTransform leftWobble = CGAffineTransformRotate(CGAffineTransformIdentity, RADIANS(-5.0));
    CGAffineTransform rightWobble = CGAffineTransformRotate(CGAffineTransformIdentity, RADIANS(5.0));
    
    itemView.transform = leftWobble;  // starting point
    
    [UIView beginAnimations:@"wobble" context:itemView];
    [UIView setAnimationRepeatAutoreverses:YES]; // important
    [UIView setAnimationRepeatCount:10];
    [UIView setAnimationDuration:0.25];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(wobbleEnded:finished:context:)];
    
    itemView.transform = rightWobble; // end here & auto-reverse
    
    [UIView commitAnimations];
    
    ...
    
    - (void) wobbleEnded:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context 
    {
         if ([finished boolValue]) {
            UIView* item = (UIView *)context;
            item.transform = CGAffineTransformIdentity;
         }
    }
    

    Probably have to play with timing and angles but this should get you started.

    EDIT: I edited the response to add code to put the item back in its original state when done. Also, note that you can use the beginAnimations context value to pass along anything to the start/stop methods. In this case it’s the wobbling object itself so you don’t have to rely on specific ivars and the method can be used for any generic UIView-based object (i.e. text labels, images, etc.)

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

Sidebar

Related Questions

Want to verify that my understanding of how this works. Have a C++ Class
Want to make a vocabulary list in HTML & CSS that looks like this:
I have an application that lets the user enter a string. I then count
want that the navigation menu moves up & content moves left when the sidebar
I want to include more statements in the for statement. Now I do this:
Want to add a nice multiple image upload feature to a site so I
Want to write a typing test application (GUI, windows). Is simple terms. app shows
want my table to show up only half way from the bottom of the
Want to display the splash page for iphone and android web browser. I am
Want an applescript droplet that opens files in QuickTime and mutes them all. The

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.