IOS實現(xiàn)視頻動畫效果的啟動圖
先上效果圖
實現(xiàn)思路
主要思路就是用一個控制器來作為播放視頻的載體,然后在讓這個控制器作為根視圖,視頻播放完成之后那就該干嘛干嘛了。
話不多說了,下面就放代碼好了
先新建一個控制器AnimationViewController
在控制器中新建一個屬性moviePlayer
,記得要先引入系統(tǒng)庫<MediaPlayer/MediaPlayer.h>
@property (nonatomic, strong) MPMoviePlayerController *moviePlayer;
設(shè)置moviePlayer
我是在懶加載中直接設(shè)置的
-(MPMoviePlayerController *)moviePlayer{ if (!_moviePlayer) { _moviePlayer = [[MPMoviePlayerController alloc]init]; [_moviePlayer.view setFrame:self.view.bounds]; //設(shè)置自動播放 [_moviePlayer setShouldAutoplay:NO]; //設(shè)置源類型 因為新特性一般都是播放本地的小視頻 所以設(shè)置源類型為file _moviePlayer.movieSourceType = MPMovieSourceTypeFile; //取消控制視圖 如:播放暫停等 _moviePlayer.controlStyle = MPMovieControlStyleNone; [self.view addSubview:_moviePlayer.view]; //監(jiān)聽播放完成 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(playFinsihed) name:MPMoviePlayerPlaybackDidFinishNotification object:nil]; } return _moviePlayer; }
然后在.h
中公開一個moviePath
視頻的路徑,還有一個結(jié)束播放的blockplayFinished
等下需要。
AnimationViewController
中也算差不多了,畢竟也沒什么東西,接下來我們?nèi)?code>AppDelegate中聲明一個AnimationViewController
屬性
- (AnimationViewController *)animationViewController{ if (!_animationViewController) { _animationViewController = [[AnimationViewController alloc]init]; //設(shè)置本地視頻路徑 _animationViewController.moviePath = [[NSBundle mainBundle] pathForResource:@"V" ofType:@"mp4"]; _animationViewController.playFinished = ^{ UINavigationController *rootNav = [[UINavigationController alloc] initWithRootViewController:[[ViewController alloc] init]]; [UIApplication sharedApplication].keyWindow.rootViewController = rootNav; }; } return _animationViewController; }
然后在AppDelegate
的啟動方法把這個控制器設(shè)為根視圖
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds]; self.window.rootViewController = self.animationViewController; [self.window makeKeyAndVisible]; return YES; }
總結(jié)
這里要說一句,剛開始我用這個路徑但是一直為空,后來我添加了一個名字為Resource的文件夾把mp4放進(jìn)去就好了,以上就是這篇文章的全部內(nèi)容了,有需要的朋友們可以參考借鑒。
相關(guān)文章
iOS UITextView 首行縮進(jìn) 撤銷輸入 反撤銷輸入的實現(xiàn)代碼
本文是腳本之家小編給大家分享的iOS UITextView 首行縮進(jìn) 撤銷輸入 反撤銷輸入的實現(xiàn)代碼,需要的朋友參考下吧2017-09-09IOS UI學(xué)習(xí)教程之使用代碼創(chuàng)建button
這篇文章主要為大家詳細(xì)介紹了IOS UI學(xué)習(xí)教程之使用代碼創(chuàng)建button,感興趣的小伙伴們可以參考一下2016-03-03