我在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. }更多推荐
每次打开应用程序时运行动画
发布评论