關(guān)于給iOS設(shè)置一個開機動畫.

之前給應(yīng)用加入一個開機的閃屏圖片,只要設(shè)置在images.xcassets哪里設(shè)置好LaunchImage的圖片,那么應(yīng)用開啟的時候就會顯示這張圖片指導(dǎo)加載完畢.

最近老板心血來潮,說要把開機圖片換成一個3秒左右的視頻.好吧,滿足一下老板的虛榮心. (雖然明天離職了,但是工作還是要做的嘛) 于是尋思著如何去實現(xiàn)它.

StackOverFlow 有一篇關(guān)于這個方法的視線思路 Emulating splash video in iOS application

我實現(xiàn)好的具體的思路大概是這樣:

1.先把LaunchImage這圖換成黑色或者刪除.
2.在載入之后調(diào)用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];
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容