gpt4 book ai didi

ios removeAllAnimations 不工作

转载 作者:行者123 更新时间:2023-11-28 22:17:46 25 4
gpt4 key购买 nike

我有一个永远的动画,但我想在某个时候停止它我尝试了 removeAllAnimations 但它没有用。这是我的代码。

[self.backgroundImageView.layer removeAllAnimations];

-(void)animateToLeft{
if(isInCenter){
[UIView animateWithDuration:10.0f animations:^{
backgroundImageView.frame = CGRectMake(kLeftX, 0, kBackgroundWidth, kBackgroundHeight);
}completion:^(BOOL finished) {
[self animateToRight];
}];
isInCenter = NO;
}
else{
[UIView animateWithDuration:20.0f animations:^{
backgroundImageView.frame = CGRectMake(kLeftX, 0, kBackgroundWidth, kBackgroundHeight);
}completion:^(BOOL finished) {
[self animateToRight];
}];
}

}

-(void)animateToRight{
[UIView animateWithDuration:20.0f animations:^{
backgroundImageView.frame = CGRectMake(kRightX, 0, kBackgroundWidth, kBackgroundHeight);
}completion:^(BOOL finished) {
[self animateToLeft];
}];
}

最佳答案

This will not work in your situation.

因为 [self.backgroundImageView.layer removeAllAnimations]; 这将删除所有已经由 [self.backgroundImageView.layer addAnimation:/*CABasicAnimation 应该添加在这里*/];

您可以通过在完成时设置 bool 变量来停止此循环,然后检查 bool 变量。

关于ios removeAllAnimations 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21202669/

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