IOS实现视频动画效果的启动图
先上效果图

实现思路
主要思路就是用一个控制器来作为播放视频的载体,然后在让这个控制器作为根视图,视频播放完成之后那就该干嘛干嘛了。
话不多说了,下面就放代码好了
先新建一个控制器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放进去就好了,以上就是这篇文章的全部内容了,有需要的朋友们可以参考借鉴。
相关文章
Flutter Widgets粘合剂CustomScrollView NestedScrollVie
这篇文章主要为大家介绍了Flutter Widgets粘合剂CustomScrollView NestedScrollView滚动控件示例详解,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪2022-11-11
iOS设置UIButton文字显示位置和字体大小、颜色的方法
这篇文章给大家分享了iOS如何设置UIButton的文字显示位置和字体的大小、颜色,文中给出了示例代码,相信对大家的学习和理解很有帮助,有需要的朋友们下面来一起看看吧。2016-09-09


最新评论