iPhone:重新启动循环动画视图隐藏后,然后又重新出现? [英] iphone: Restart looping animation after view is hidden, then reappears?

查看:167
本文介绍了iPhone:重新启动循环动画视图隐藏后,然后又重新出现?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序有两种不同的看法标签栏。在第一个选项卡,其观点具有连续,循环动画。

My app has a tab bar with two different views. On the first tab, its view has a continuously-looping animation.

当我点击第二个选项卡,然后再回到第一个,动画已停止。我知道我可以在viewWillAppear中再次启动:方法,但问题是比大。具体来说,动画也将停止,如果应用程序转移到后台的状态,然后恢复到前台。在这种情况下,viewWillAppear中未于前景过渡叫,所以viewWillAppear中技术不会做任何事情。

When I click on the second tab, then go back to the first, the animation has stopped. I know I could start it again in a viewWillAppear: method, but the problem is bigger than that. Specifically, the animation will also stop if the app transitions to the background state, then moves back to the foreground. In that case, viewWillAppear is not called upon the foreground transition, so the viewWillAppear technique wouldn't do anything.

什么是处理这种情况的最好方法?

What's the best way to handle this situation?

感谢。

推荐答案

要保持封装,你理所当然地不想让你的的AppDelegate 来知道哪些意见需要恢复动画。但是你可以有一个包含动画寄存器(在视图的的init 法为例)相应的通知视图,并重新启动本身的动画。

To maintain encapsulation, you rightly don't want your AppDelegate to know which views need to resume animations. But you can have the view that contains the animation register for corresponding notification (for example in the view's init method) and restart the animation on itself.

[[NSNotificationCenter defaultCenter] 
   addObserver:self 
      selector:@selector(startAnimation) 
          name:UIApplicationWillEnterForegroundNotification  
        object:nil];

...不要忘记从通知中心中的注销的dealloc 方法。

这篇关于iPhone:重新启动循环动画视图隐藏后,然后又重新出现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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