gpt4 book ai didi

iphone - iOS,退出后台时重启动画

转载 作者:IT王子 更新时间:2023-10-29 08:04:23 27 4
gpt4 key购买 nike

当我的应用退出后台时,动画已停止。这是正常的。但我想从当前状态重新开始我的动画。我该怎么做才能不到处乱拍。

[UIView animateWithDuration:60 delay:0 options:(UIViewAnimationOptionCurveLinear |UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat | UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionBeginFromCurrentState) animations:^{
[bg setFrame:CGRectMake(0, 0, 1378, 1005)];
} completion:nil];

我试着在动画前面放一个固定的框架,但这只会让它卡住。

[bg setFrame:CGRectMake(0, 0, 1378, 1005)];

有什么想法吗?

最佳答案

您可以在您的类中为 UIApplicationWillEnterForegroundNotification 添加一个观察者:

- (void)addNotifications { 
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillEnterForeground) name:UIApplicationWillEnterForegroundNotification object:nil];
}

- (void)applicationWillEnterForeground {
[self animate];
}

- (void)animate {
[bg setFrame:CGRectMake(0, 0, 0, 0)];
[UIView animateWithDuration:60 delay:0 options:(UIViewAnimationOptionCurveLinear |UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat | UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionBeginFromCurrentState) animations:^{
[bg setFrame:CGRectMake(0, 0, 1378, 1005)];
} completion:nil];
}

设置动画的开始状态很重要(并且不要忘记移除通知观察者)

关于iphone - iOS,退出后台时重启动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6042472/

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