iOS,退出后台时重新启动动画 [英] iOS, Restarting animation when coming out of the background

查看:157
本文介绍了iOS,退出后台时重新启动动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我的应用程序退出后台时,动画停止了。这是正常的。但我想从当前状态重新启动我的动画。如果没有我到处捕捉,我怎么做呢。

when my app comes out of the background the animation has stopped. which is normal. but i want to restart my animation from the current state. how do i do that without my snapping all over the place.

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

我尝试在动画前放置一个设定的框架,但这只是让它快速移动。

i tried putting a set frame in front of the animation but that just makes it snap.

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

任何想法?

推荐答案

@ dany_23的答案可行。

well the answer of @dany_23 could work.

但是我遇到了另一种方法,如果您不需要恢复动画但重新启动动画就可以正常工作,而在重新激活时没有视图或图层对齐

But I came across an other method that works just fine if you don't need to resume your animation but restart your animation, without the view or layer snapping when you reactivate the app.

in the

: (UIApplication *)application

- (void)applicationWillResignActive:(UIApplication *)application

你在viewcontroller中调用一个实现以下代码的方法。

you call a method in your viewcontroller which implements the following code.

[view.layer removeAllAnimations];
 // this following CGRect is the point where your view originally started 
[bg setFrame:CGRectMake(0, 0, 1378, 1005)]; 

- (void)applicationDidBecomeActive:(UIApplication *)application

你调用一个方法在你刚启动动画的viewcontroller中。
类似

you call a method in your viewcontroller that just starts the animation. something like

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

希望这会有所帮助,感谢所有回复的人。

Hope this helps, Thanks to all who replied.

这篇关于iOS,退出后台时重新启动动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆