Smooth transition from launch image to main view

前端 未结 4 1291
伪装坚强ぢ
伪装坚强ぢ 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];
                         }
        ];
    }
    

提交回复
热议问题