我在我的UIView上有多个基于用户触摸动画/交互的动画/交互式UIImageViews。我试图添加一个功能,该功能可以通过触摸图标来“摆动”这些可动画/交互式UIImageView,这将帮助用户识别屏幕上的哪些对象是交互式的。我尝试使用下面的代码从this博客实现“摆动”运动:摆动动画在目标C
-(void)doWiggle:(UIView *)touchView {
// grabbing the layer of the tocuhed view.
CALayer *touchedLayer = [touchView layer];
// here is an example wiggle
CABasicAnimation *wiggle = [CABasicAnimation animationWithKeyPath:@"transform"];
wiggle.duration = 0.1;
wiggle.repeatCount = 1e100f;
wiggle.autoreverses = YES;
wiggle.toValue = [NSValue valueWithCATransform3D:CATransform3DRotate(touchedLayer.transform,0.1, 0.0 ,1.0 ,1.0)];
// doing the wiggle
[touchedLayer addAnimation:wiggle forKey:@"wiggle"];
// setting a timer to remove the layer
[NSTimer scheduledTimerWithTimeInterval: 2.0 target:self selector:@selector(endWiggle:) userInfo:touchedLayer repeats:NO];
}
-(void)endWiggle:(NSTimer*)wiggleTimer {
// stopping the wiggle now
[((CALayer*)wiggleTimer.userInfo) removeAllAnimations];
}
我这样称呼它在我的例行:[self doWiggle:imageAnimation];
其中imageAnimation是的UIImageView。我看到,在摆动的同时,一半的图像正在消失。我在某处阅读我需要正确设置z-index才能使其工作。我需要为z-index设置什么?并且每页有3到4个UIImageView,我需要调用doWiggle:例程,我是否需要修复所有这些UIImageView的z索引?
没有必要安排一个计时器去除,只需将您的重复计数设置为2.0/0.1。动画在完成时会自动从图层中移除。 – nielsbot