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

孤人 提交于 2019-12-02 14:58:37

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)

with blocks (iOS 4+) it would look like:

#define RADIANS(degrees) ((degrees * M_PI) / 180.0)

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

    cell.transform = leftWobble;  // starting point
    cell.deleteButton.hidden = NO;

    [UIView animateWithDuration:0.125 delay:0 options:(UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse) animations:^{
        cell.transform = rightWobble;
    }completion:^(BOOL finished){
    }];

If you mean icons in the main screen of iOS, I don't think it would be ever possible.

Of course, if you mean icons inside your application, you can do whatever you want.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!