IOS實(shí)現(xiàn)視頻動(dòng)畫效果的啟動(dòng)圖
先上效果圖

實(shí)現(xiàn)思路
主要思路就是用一個(gè)控制器來作為播放視頻的載體,然后在讓這個(gè)控制器作為根視圖,視頻播放完成之后那就該干嘛干嘛了。
話不多說了,下面就放代碼好了
先新建一個(gè)控制器AnimationViewController在控制器中新建一個(gè)屬性moviePlayer,記得要先引入系統(tǒng)庫(kù)<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è)置自動(dòng)播放
[_moviePlayer setShouldAutoplay:NO];
//設(shè)置源類型 因?yàn)樾绿匦砸话愣际遣シ疟镜氐男∫曨l 所以設(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中公開一個(gè)moviePath視頻的路徑,還有一個(gè)結(jié)束播放的blockplayFinished等下需要。
AnimationViewController中也算差不多了,畢竟也沒什么東西,接下來我們?nèi)?code>AppDelegate中聲明一個(gè)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的啟動(dòng)方法把這個(gè)控制器設(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é)
這里要說一句,剛開始我用這個(gè)路徑但是一直為空,后來我添加了一個(gè)名字為Resource的文件夾把mp4放進(jìn)去就好了,以上就是這篇文章的全部?jī)?nèi)容了,有需要的朋友們可以參考借鑒。
相關(guān)文章
Flutter Widgets粘合劑CustomScrollView NestedScrollVie
這篇文章主要為大家介紹了Flutter Widgets粘合劑CustomScrollView NestedScrollView滾動(dòng)控件示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-11-11
iOS設(shè)置UIButton文字顯示位置和字體大小、顏色的方法
這篇文章給大家分享了iOS如何設(shè)置UIButton的文字顯示位置和字體的大小、顏色,文中給出了示例代碼,相信對(duì)大家的學(xué)習(xí)和理解很有幫助,有需要的朋友們下面來一起看看吧。2016-09-09
iOS中應(yīng)用內(nèi)添加指紋識(shí)別的實(shí)例代碼
iOS8之后蘋果發(fā)布了指紋識(shí)別的功能,通過touch ID來識(shí)別用戶,做用戶授權(quán),主要是依賴于LocalAuthentication庫(kù),下面通過本文給大家介紹iOS中應(yīng)用內(nèi)添加指紋識(shí)別的實(shí)例代碼,一起看看吧2016-12-12
簡(jiǎn)單好用可任意定制的iOS Popover氣泡效果
Popover(氣泡彈出框/彈出式氣泡/氣泡)是由一個(gè)矩形和三角箭頭組成的彈出窗口,箭頭指向的地方通常是導(dǎo)致Popover彈出的控件或區(qū)域。本文通過實(shí)例代碼給大家介紹了iOS Popover氣泡效果,需要的朋友參考下吧2017-12-12

