每次打开应用程序时运行动画 [英] run animation every time app is opened

查看:168
本文介绍了每次打开应用程序时运行动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在viewDidLoad中有一个动画,该动画在应用程序首次启动时运行。如果您退出应用程序,然后再次启动它,则动画将不会播放。

I have an animation in viewDidLoad that runs the first time the app is launched. if you exit the app, then launch it again the animation doesn't play.

我将如何使动画每次打开应用程序时播放,

how would I go about making the animation play each and every time the app is opened,

感谢您的帮助

推荐答案

在iOS 4中,按主页按钮不会终止应用程序,而是会挂起它。当应用再次激活时,会发布 UIApplicationDidBecomeActiveNotification 。注册该通知并在您的处理程序中启动动画。

In iOS 4, pressing the home button doesn't terminate the app, it suspends it. When the app is made active again, a UIApplicationDidBecomeActiveNotification is posted. Register for that notification and initiate the animation in your handler.

编辑:下面添加了代码。

这是一种方法:让您的视图控制器成为 viewWillAppear: UIApplicationDidBecomeActiveNotification 的观察者:

Here's one way to do it: Have your view controller become an observer of UIApplicationDidBecomeActiveNotification in its viewWillAppear: method.

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(performAnimation:) name:UIApplicationDidBecomeActiveNotification object:nil];
}

在视图控制器的 viewDidDisappear中取消注册通知: 方法。

- (void)viewDidDisappear:(BOOL)animated {
    [super viewDidDisappear:animated];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidBecomeActiveNotification object:nil];
}

最后,将动画代码放入注册时指定的选择器中以接收通知

Finally, put your animation code in the selector specified when registering to receive the notification.

- (void)performAnimation:(NSNotification *)aNotification {
    // Animation code.
}

这篇关于每次打开应用程序时运行动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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