我只想在 didFinishLaunchingWithOptions 中用动画显示视图,我的代码如下所示:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
CGRect finalRect = CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height);
UIImage *image = [UIImage imageNamed:@"122.jpg"];
UIButton* pic = [[UIButton alloc] initWithFrame:finalRect];
[pic setBackgroundImage:image forState:UIControlStateNormal];
[pic setHidden:true];
pic.center = CGPointMake(finalRect.size.width / 2, finalRect.size.height / 2);
UIViewController* controller = [[UIViewController alloc] init];
[controller setView:pic];
[self.window setRootViewController:controller];
[self.window makeKeyAndVisible];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:2.5];
[pic setHidden:false];
[UIView commitAnimations];
return YES;
}
但动画根本不起作用。屏幕上突然出现了带有图片的子视图。但是,如果我使用按钮触发动画代码,视图将按预期显示动画。didFinishLaunchingWithOptions 是否有任何限制?
PS:
这个问题通过将动画代码移动到控制器的 viewDidAppear proc 中来解决,就像下面的 rokjarc 所说。
但是还有另一种解决方案,方法是在从 didFinishLaunchingWithOptions 调用的延迟例程中执行动画代码,例如:
[self performSelector:@selector(executeAnimation) withObject:nil afterDelay:1];