我想在我的视图中添加一个心跳效果,一种方法是使用UIView的动画方法如下:
- (void)heartBeating
{
UIView *panel;
NSTimeInterval during = 0.8;
[UIView animateKeyframesWithDuration:during delay:0.0
options:UIViewKeyframeAnimationOptionCalculationModeLinear|UIViewKeyframeAnimationOptionRepeat
animations:^{
[UIView addKeyframeWithRelativeStartTime:0.0 relativeDuration:0.4 animations:^{
panel.transform = CGAffineTransformMakeScale(1.2, 1.2);
}];
[UIView addKeyframeWithRelativeStartTime:0.4 relativeDuration:0.6 animations:^{
panel.transform =CGAffineTransformIdentity ;
}];
} completion:^(BOOL finished) {
}];
}
问题是:如果我想停止动画在一个动作中,例如,一个停止屁股点击,我该怎么做。
我知道我可以通过创建CAKeyFrameAnimation
并将其添加到视图中来实现相同的效果' CALayer .但是我想知道如何使用UIView的动画方法。谢谢。
尝试
[panel1.layer removeAllAnimations];
希望这对您有所帮助。