所以我知道Default.png可用于iPhone应用程序中的启动画面,但我发现它看起来不专业,因为一旦应用程序完成加载就没有动画。
所以我试图添加一个会淡出的闪屏,然后转到上一个上一个视图。
互联网上的大多数示例都倾向于使用addSubview的旧方式。我如何将其添加到我的故事板应用程序中。
当前代码(时间错误,因为我不确定它最初是否正常工作)
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
splashView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Default2.png"]];
splashView.frame = CGRectMake(0, 0, 324, 480);
[_window addSubview:splashView];
[_window bringSubviewToFront:splashView];
[_window makeKeyAndVisible];
[self performSelector:@selector(removeSplash) withObject:nil afterDelay:1500.2];
return YES;
}
-(void)removeSplash;
{
[UIView animateWithDuration:1.0 animations:^{self.splashView.alpha = 0.0;} completion:^(BOOL finished){ [splashView removeFromSuperview]; }];
[splashScreen release];
}
答案 0 :(得分:3)
除了Guntis Treulands之外,我还有另一种方法可以在不将动画代码移出- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
方法的情况下完成此操作。
只需将您的splashView直接添加到_window.rootViewController.view
。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIImage *splashImage = [UIImage autoAdjustImageNamed:@"Default.png"];
UIImageView *splashImageView = [[UIImageView alloc] initWithImage:splashImage];
[self.window.rootViewController.view addSubview:splashImageView];
[self.window.rootViewController.view bringSubviewToFront:splashImageView];
[UIView animateWithDuration:1.5f
delay:2.0f
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
splashImageView.alpha = .0f;
CGFloat x = -60.0f;
CGFloat y = -120.0f;
splashImageView.frame = CGRectMake(x,
y,
splashImageView.frame.size.width-2*x,
splashImageView.frame.size.height-2*y);
} completion:^(BOOL finished){
if (finished) {
[splashImageView removeFromSuperview];
}
}];
return YES;
}
答案 1 :(得分:1)
在你的情况下,我仍然会将其添加为子视图,但始终将其保留为窗口的顶级子视图。当它是alpha == 0
时,它将停止接收触摸。所以......没有理由每次想要淡出它时都要释放它。
就我而言 - 客户希望每次应用程序最大化或打开时都能看到启动画面,所以我也这样做了:
- (void)applicationDidEnterBackground:(UIApplication *)application
{
extraSplashScreen.alpha = 1; //when it goes in background - set splash screen visible.
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
[self fadeOutSplash]; //initiate fade out.
}
我的fadeOutSplash
函数看起来像这样(以防万一):
- (void)fadeOutSplash
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationDuration:0.3];
[UIView setAnimationDelay:0.5];
extraSplashScreen.alpha = 0;
[UIView commitAnimations];
}
希望有所帮助。