之前給應(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];
}