uiimageview - 如何在 uiimageview 上放置抖动动画?

标签 uiimageview cabasicanimation

我一直在尝试实现这一点,但找不到任何可以在删除它们时像 iPhone 应用程序抖动一样抖动它的代码!

CABasicAnimation *animation = 
                         [CABasicAnimation animationWithKeyPath:@"position"];
[animation setDuration:0.05];
[animation setRepeatCount:8];
[animation setAutoreverses:YES];
[animation setFromValue:[NSValue valueWithCGPoint:
               CGPointMake([lockView center].x - 20.0f, [lockView center].y)]];
[animation setToValue:[NSValue valueWithCGPoint:
               CGPointMake([lockView center].x + 20.0f, [lockView center].y)]];
[[lockView layer] addAnimation:animation forKey:@"position"];

最佳答案

您可以通过以下代码实现此目的,您已经定义了从和到的旋转角度。

CABasicAnimation* anim = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
   [anim setToValue:[NSNumber numberWithFloat:0.0f]];
   [anim setFromValue:[NSNumber numberWithDouble:M_PI/16]]; // rotation angle
   [anim setDuration:0.1];
   [anim setRepeatCount:NSUIntegerMax];
   [anim setAutoreverses:YES];
   [[imageView layer] addAnimation:anim forKey:@"iconShake"];

关于uiimageview - 如何在 uiimageview 上放置抖动动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16891720/

相关文章:

ios - Xcode segue 与 UIImageView

ios - CAShapeLayer 在动画 Swift 期间检测触摸

ios8 - iOS 8动画错误

ios - 当从 viewDidLoad 调用该方法时,CABasicAnimation 不起作用

iphone - 在 TabBar 中的 View Controller 之间共享 UIImageView

ios - 将调整大小的图像从 Core Data 插入 UICollectionView 的最简单方法是什么?

iOS - 表格 View 单元格无法正确呈现

iphone - 如何从服务器导入图像并将其排列在 View 中

ios - 使用 CAKeyframeAnimation 动画图层位置

swift - iOS Swift - 如何使用 CABasicAnimation 和 CATransform3DRotate 以及 "m34"变换来制作 360 度翻转动画?