如何使图像在iPhone主屏幕上摇摆?

Poo*_*oja 10 iphone core-animation objective-c ios

我的应用程序中有很多图标,我想以类似于尝试从iPhone主屏幕删除应用程序时的方式设置动画.你怎么能这样做?

此外,有没有办法让图标以类似于解锁iPhone时的方式激活到屏幕上?

Tig*_*ing 26

如果你想让你的视图,图像等摆动,比如主屏幕,你可以这样做:

    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];
Run Code Online (Sandbox Code Playgroud)

您还需要添加此定义:

#define RADIANS(degrees) ((degrees * M_PI) / 180.0)
Run Code Online (Sandbox Code Playgroud)


Fre*_*nda 10

使用块(iOS 4+)它看起来像:

#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){
    }];
Run Code Online (Sandbox Code Playgroud)

  • 我认为可以添加两件事.| UIViewAnimationOptionAllowUserInteraction如果按钮是运行动画的视图的子项.//无论出于何种原因移除摆动动画[self.view.layer removeAllAnimations]; 导入#import <QuartzCore/QuartzCore.h> (3认同)