我像这样制作(移动)子类 UIImageView 的动画:
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration: 1];
[UIView setAnimationDelay:0];
[UIView setAnimationCurve: UIViewAnimationCurveEaseOut];
[UIView setAnimationBeginsFromCurrentState:YES];
if (position == 0) position = 1;
if (position > 6) position--;
self.transform = CGAffineTransformMakeTranslation(position*120, 0);
[UIView commitAnimations];
然后,我想通过让它跳动来突出显示它:
CAKeyframeAnimation *bounce = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
CATransform3D forward = CATransform3DMakeScale(1.3, 1.3, 1);
CATransform3D back = CATransform3DMakeScale(0.7, 0.7, 1);
CATransform3D forward2 = CATransform3DMakeScale(1.2, 1.2, 1);
CATransform3D back2 = CATransform3DMakeScale(0.9, 0.9, 1);
[bounce setValues:[NSArray arrayWithObjects:
[NSValue valueWithCATransform3D:CATransform3DIdentity],
[NSValue valueWithCATransform3D:forward],
[NSValue valueWithCATransform3D:back],
[NSValue valueWithCATransform3D:forward2],
[NSValue valueWithCATransform3D:back2],
[NSValue valueWithCATransform3D:CATransform3DIdentity],
nil]];
[bounce setDuration:0.6];
[[super layer] addAnimation:bounce forKey:@"bounceanimation"];
这一切都有效。它移动了 120 像素,但是当调用脉动代码时,它会在其原始位置脉动,而不是我刚刚移动它的位置。这是为什么?我该如何改变它?
托比亚斯
最佳答案
好的,这是你的问题:
self.transform = CGAffineTransformMakeTranslation(position*120, 0);
请注意,您正在将 View 平移到另一个位置,但与任何变换一样,对象的原始统计信息保持不变。
您所要做的就是将该代码转换为 setFrame: 方法,以便它实际移动图像。
关于iphone - 动画 UIView - 如何跟踪位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9947240/