我想在我的应用程序中来回摆动图像,类似于当你按下它时iPhone图标的摆动.最好的方法是什么?
这是我第一次涉足不使用动画GIF的动画.我认为这个想法是来回轻微旋转图像以产生摆动效果.我已经看过使用CABasicAnimation和CAKeyframeAnimation.CABasicAnimation每次重复时都会创建一个抖动,因为它会跳转到from位置并且不会向内插回.CAKeyframeAnimation似乎是解决方案,除了我无法让它工作.我肯定错过了什么.这是我使用CAKeyframeAnimation的代码(不起作用):
NSString *keypath = @"wobbleImage";
CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:keypath];
animation.duration = 1.0f;
animation.delegate = self;
animation.repeatCount = 5;
CGFloat wobbleAngle = 0.0872664626f;
NSValue *initial = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(0.0f, 0.0f, 0.0f, 1.0f)];
NSValue *middle = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(wobbleAngle, 0.0f, 0.0f, 1.0f)];
NSValue *final = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(-wobbleAngle, 0.0f, 0.0f, 1.0f)];
animation.values = [NSArray arrayWithObjects:initial, middle, final, nil];
[imageView.layer addAnimation:animation forKey:keypath];
Run Code Online (Sandbox Code Playgroud)
或者可能有一个我只是缺少的完全简单的解决方案.感谢任何指针.谢谢!
我们目前正在开发一个包含一系列图标的应用程序.我们希望图标在按下时像应用程序删除动画一样摆动.编码这个动画序列的最佳方法是什么?
我有一个UIImageView我想旋转180度,占用1秒,然后我想在此位置等待1秒,然后将180度旋转回到原始位置,占用1秒。
我该如何完成?我尝试了100种方法,但它会不断回弹而不是回滚
编辑:我忘了补充,我需要这个无限期地重复