gpt4 book ai didi

animation - 如何使用 UIViewKeyframeAnimationOptionRepeat 选项停止 [UIView animateKeyframesWithDuration] 的动画

转载 作者:行者123 更新时间:2023-12-04 03:04:25 24 4
gpt4 key购买 nike

我想在 View 中添加心跳效果,一种方法是使用 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) {

}];
}

问题是:如果我想在一个 Action 中停止动画,例如,点击一个停止按钮,我该怎么做。

我知道我可以通过创建 CAKeyFrameAnimation 并将其添加到 View 的 CALayer 来实现相同的效果。但是我想知道如何处理 UIView 的动画方法。谢谢。

最佳答案

试试

[panel1.layer removeAllAnimations];

希望这会对你有所帮助。

关于animation - 如何使用 UIViewKeyframeAnimationOptionRepeat 选项停止 [UIView animateKeyframesWithDuration] 的动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27263006/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com