【发布时间】:2011-12-08 02:55:04
【问题描述】:
我有一个非常简单的 UIView 动画,它会导致我的视图“跳动”:
[UIView animateWithDuration:0.2 delay:0.0f options:UIViewAnimationOptionAllowUserInteraction+UIViewAnimationOptionRepeat+UIViewAnimationOptionAutoreverse animations:^{
CGAffineTransform transf = CGAffineTransformScale(self.view.transform, 1.05f, 1.05f);
[self.view setTransform:transf];
} completion:nil];
在某些时候,用户点击按钮取消动画,并应用新的变换。
[self.view.layer removeAllAnimations];
[self.view setTransform:aNewTransform];
我希望它重置为原始变换,但它的大小却增加了 5%。
编辑:我尝试添加一个完成块,将转换重置为其原始位置。这可行,但会导致我在之后立即运行的转换被践踏......完成块在我应用aNewTransform 之后运行。
编辑 2:我找到了一个解决方案,使用 CABasicAnimation,而不是 UIView 动画。如果有人找到使用 UIView 动画的解决方案,我仍然会感兴趣......我更喜欢基于块的界面。这也只有效,因为我碰巧跟踪我的比例值与应用于视图的比例值分开。改变尺度的一切都使用了同样改变的方法self.scale
我的替换动画:
CABasicAnimation *basicAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
basicAnimation.toValue = [NSNumber numberWithFloat:self.scale*1.05f];
basicAnimation.fromValue = [NSNumber numberWithFloat:self.scale];
basicAnimation.autoreverses = YES;
basicAnimation.duration = 0.2;
basicAnimation.repeatCount = HUGE_VALF;
[self.view.layer addAnimation:basicAnimation forKey:@"Throb"];
【问题讨论】:
标签: ios uiview core-animation uiviewanimation