Smooth transition from launch image to main view

前端 未结 4 1253
伪装坚强ぢ
伪装坚强ぢ 2020-12-13 22:40

Is it possible to implement a smooth transition when the app loads, from the launch image to the first view?

The default behavior is on/off, with an immediate change

相关标签:
4条回答
  • 2020-12-13 23:02

    Modified Dancreek's answer to do it all in AppDelegate application:didFinishLaunchingWithOptions. I like this because the code is guaranteed to only run at app start, and it's not polluting any of the view controllers.

    It's very simple:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    
        // set up your root view and stuff....
    
        //.....(do whatever else you need to do)...
    
        // show the main window, overlay with splash screen + alpha dissolve...
    
            UIImageView *splashScreen = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Default.png"]];
        [self.window addSubview:splashScreen];        
        [self.window makeKeyAndVisible];
    
        [UIView animateWithDuration:0.3 animations:^{splashScreen.alpha = 0.0;}
                         completion:(void (^)(BOOL)) ^{
                                 [splashScreen removeFromSuperview];
                         }
        ];
    }
    
    0 讨论(0)
  • 2020-12-13 23:05

    You are in luck. I just did this a few min ago. You need a splash screen. An image on your view that is exactly the same as your default image that the device loads. Then in your app have it dismiss with a fade animation called from the viewDidAppear function

    - (void)viewDidAppear:(BOOL)animated
    {
        [super viewDidAppear:animated];
        [self performSelector:@selector(killSplashScreen) withObject:nil afterDelay:1.0];
    
    }
    
    - (void)killSplashScreen {
        [UIView animateWithDuration:0.5 animations:^{splashScreen.alpha = 0.0;} completion:NULL];
    }
    
    0 讨论(0)
  • 2020-12-13 23:09

    There's no framework support, but you can get that result if you do it yourself, manually. Depending on what your launch image is, and what your UI looks like, you can do it in different ways, but basically: make your first view controller load and display your default.png image in an image view when it loads up. Then animate a fade out of that image to reveal your actual UI.

    0 讨论(0)
  • 2020-12-13 23:19

    We often use something called "splashView" to do this. It was written by Shannon Applecline and available under the CC license. You will have to do some Googling to find it.

    //
    //  splashView.h
    //  version 1.1
    //
    //  Created by Shannon Appelcline on 5/22/09.
    //  Copyright 2009 Skotos Tech Inc.
    //
    //  Licensed Under Creative Commons Attribution 3.0:
    //  http://creativecommons.org/licenses/by/3.0/
    //  You may freely use this class, provided that you maintain these attribute comments
    //
    //  Visit our iPhone blog: http://iphoneinaction.manning.com
    //
    
    0 讨论(0)
提交回复
热议问题