关于给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];
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容