关于给iOS设置一个开机动画.

之前给应用加入一个开机的闪屏图片,只要设置在images.xcassets哪里设置好LaunchImage的图片,那么应用开启的时候就会显示这张图片指导加载完毕.

最近老板心血来潮,说要把开机图片换成一个3秒左右的视频.好吧,满足一下老板的虚荣心. (虽然明天离职了,但是工作还是要做的嘛) 于是寻思着如何去实现它.

StackOverFlow 有一篇关于这个方法的视线思路 Emulating splash video in iOS application

我实现好的具体的思路大概是这样:

1.先把LaunchImage这图换成黑色或者删除.
2.在载入之后调用MPMoviePlayerController播放器, 全屏播放必须隐藏进度条.

代码如下

-(void) openAnimation{                
    NSBundle *bundle = [NSBundle mainBundle];
    if(bundle != nil)
    {
        NSURL *movieURL;
        NSString *moviePath = [bundle pathForResource:@"OpenAnimation" ofType:@"mp4"];
        if (moviePath)
        {
            movieURL = [NSURL fileURLWithPath:moviePath];
            MPMoviePlayerViewController* mMoviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL];
            id lastRootVC = self.window.rootViewController;
            [[NSNotificationCenter defaultCenter] addObserverForName:MPMoviePlayerPlaybackDidFinishNotification  object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *note) {
                self.window.rootViewController = lastRootVC;
            }];
            mMoviePlayer.moviePlayer.controlStyle = MPMovieControlStyleNone;
            mMoviePlayer.moviePlayer.scalingMode = MPMovieScalingModeFill;
            self.window.rootViewController = mMoviePlayer;
            NSLog(@"%@",self.window.rootViewController);
            [mMoviePlayer.moviePlayer setFullscreen:YES animated:NO];
            [mMoviePlayer.moviePlayer play];
        }
    }
}
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
        [self openAnimation];
}

你可能感兴趣的:(关于给iOS设置一个开机动画.)