我的 UIView 上有多个可动画/交互式 UIImageViews,它们会根据用户触摸进行动画/交互。我正在尝试添加一个功能,该功能将在触摸图标时“摆动”这些动画/交互式 UIImageView,这将帮助用户识别哪些对象在屏幕上是交互式的。我正在尝试使用以下代码来实现此博客中的“摆动”运动:
-(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 个 UIImageViews 我需要调用 doWiggle: 例程,我需要修复所有这些 UIImageViews 的 z-indexes 吗?