2011-10-14 58 views
0

我有一个非常简单的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"]; 

回答

0

尝试把线

[self.view setTransform:aNewTransform]; 

在完成块。

+0

将无法​​工作。 aNewTransform是假想的,可以是多种不同的转换,具体取决于使用哪个按钮。直到我删除动画才会知道。 –

2

开始在现有视图上一个新的动画之前,如果有这些属性的前面发生了改变可以重置视图:

// first, don't forget to stop ongoing animations for the view 
[theView.layer removeAllAnimations]; 

// if the view was hidden 
theView.hidden = NO; 

// if you applied a transformation e.g. translate, scale, rotate..., reset to identity 
theView.transform = CGAffineTransformIdentity; 

// if you changed the anchor point, this will reset it to the center of the view 
theView.layer.anchorPoint = CGPointMake(0.5, 0.5); 

// if you changed the alpha, this will reset it to visible 
theView.alpha = 1.;