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

前端 未结 3 1846
梦谈多话
梦谈多话 2021-01-30 09:48

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

相关标签:
3条回答
  • 2021-01-30 10:19

    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)
    
    0 讨论(0)
  • 2021-01-30 10:27

    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){
        }];
    
    0 讨论(0)
  • 2021-01-30 10:39

    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.

    0 讨论(0)
提交回复
热议问题