国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > iOS > 正文

IOS實現視頻動畫效果的啟動圖

2020-07-26 03:15:16
字體:
來源:轉載
供稿:網友

先上效果圖

實現思路

主要思路就是用一個控制器來作為播放視頻的載體,然后在讓這個控制器作為根視圖,視頻播放完成之后那就該干嘛干嘛了。

話不多說了,下面就放代碼好了

先新建一個控制器AnimationViewController在控制器中新建一個屬性moviePlayer,記得要先引入系統庫<MediaPlayer/MediaPlayer.h>

@property (nonatomic, strong) MPMoviePlayerController *moviePlayer;

設置moviePlayer我是在懶加載中直接設置的

-(MPMoviePlayerController *)moviePlayer{  if (!_moviePlayer) {    _moviePlayer = [[MPMoviePlayerController alloc]init];    [_moviePlayer.view setFrame:self.view.bounds];    //設置自動播放    [_moviePlayer setShouldAutoplay:NO];    //設置源類型 因為新特性一般都是播放本地的小視頻 所以設置源類型為file    _moviePlayer.movieSourceType = MPMovieSourceTypeFile;    //取消控制視圖 如:播放暫停等    _moviePlayer.controlStyle = MPMovieControlStyleNone;    [self.view addSubview:_moviePlayer.view];    //監聽播放完成    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(playFinsihed) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];  }  return _moviePlayer;}

然后在.h中公開一個moviePath視頻的路徑,還有一個結束播放的blockplayFinished等下需要。

AnimationViewController中也算差不多了,畢竟也沒什么東西,接下來我們去AppDelegate中聲明一個AnimationViewController屬性

- (AnimationViewController *)animationViewController{  if (!_animationViewController) {    _animationViewController = [[AnimationViewController alloc]init];    //設置本地視頻路徑    _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的啟動方法把這個控制器設為根視圖

- (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;}

總結

這里要說一句,剛開始我用這個路徑但是一直為空,后來我添加了一個名字為Resource的文件夾把mp4放進去就好了,以上就是這篇文章的全部內容了,有需要的朋友們可以參考借鑒。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 玉田县| 普兰县| 天津市| 固始县| 武隆县| 象山县| 云龙县| 九龙县| 内江市| 隆昌县| 桃源县| 长汀县| 台州市| 搜索| 屯门区| 兴海县| 郓城县| 赤城县| 东兴市| 金门县| 沙雅县| 东阿县| 五峰| 包头市| 湖州市| 寿宁县| 肥东县| 怀化市| 博乐市| 盐源县| 汉寿县| 鄂尔多斯市| 白银市| 舞阳县| 海丰县| 涞水县| 巩义市| 灵宝市| 穆棱市| 二连浩特市| 扎兰屯市|