Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you make images wobble like on the iPhone home screen?

I have many icons in my app and I would like to animate them in a manner similar to what happens when you try to delete applications from the iPhone's home screen. How can you do this?

Additionally, is there a way to have the icons animate up onto the screen in a manner similar to what happens when you unlock the iPhone?

like image 821
Pooja Avatar asked Feb 12 '11 19:02

Pooja


1 Answers

If you want to make your views, images, etc. wobble, like the home screen, you could do something like this:

    CGAffineTransform leftWobble = CGAffineTransformRotate(CGAffineTransformIdentity, RADIANS(-15.0));
    CGAffineTransform rightWobble = CGAffineTransformRotate(CGAffineTransformIdentity, RADIANS(15.0));

    view.transform = leftWobble;  // starting point

    [UIView beginAnimations:@"wobble" context:view];
    [UIView setAnimationRepeatAutoreverses:YES];
    [UIView setAnimationRepeatCount:5]; // adjustable
    [UIView setAnimationDuration:0.125];
    [UIView setAnimationDelegate:self];
    view.transform = rightWobble; // end here & auto-reverse
    [UIView commitAnimations];

You would also need to add this define:

#define RADIANS(degrees) ((degrees * M_PI) / 180.0)
like image 152
TigerCoding Avatar answered Sep 20 '22 16:09

TigerCoding