每次打开应用程序时运行动画

编程入门 行业动态 更新时间:2024-10-10 05:26:42
本文介绍了每次打开应用程序时运行动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在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. }

更多推荐

每次打开应用程序时运行动画

本文发布于:2023-11-27 15:31:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1638576.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:时运   应用程序

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!