我有一个非常简单的UIView动画,这导致我的观点为“悸动”:返回查看到原来的位置结束时的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"];
将无法工作。 aNewTransform是假想的,可以是多种不同的转换,具体取决于使用哪个按钮。直到我删除动画才会知道。 –