我一直在尝试实现这一点,但找不到任何可以在删除它们时像 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/