之前給應(yīng)用加入一個(gè)開(kāi)機(jī)的閃屏圖片,只要設(shè)置在images.xcassets哪里設(shè)置好LaunchImage的圖片,那么應(yīng)用開(kāi)啟的時(shí)候就會(huì)顯示這張圖片指導(dǎo)加載完畢.
最近老板心血來(lái)潮,說(shuō)要把開(kāi)機(jī)圖片換成一個(gè)3秒左右的視頻.好吧,滿足一下老板的虛榮心. (雖然明天離職了,但是工作還是要做的嘛) 于是尋思著如何去實(shí)現(xiàn)它.
StackOverFlow 有一篇關(guān)于這個(gè)方法的視線思路 Emulating splash video in iOS application
我實(shí)現(xiàn)好的具體的思路大概是這樣:
1.先把LaunchImage這圖換成黑色或者刪除.
2.在載入之后調(diào)用MPMoviePlayerController播放器, 全屏播放必須隱藏進(jìn)度條.
代碼如下
-(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];
}