123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- //
- // StartFigureViewController.m
- // Starbuds
- //
- // Created by 翟玉磊 on 2020/1/14.
- // Copyright © 2020 翟玉磊. All rights reserved.
- //
- #import "StartFigureViewController.h"
- @interface StartFigureViewController ()
- @property (nonatomic, readwrite, strong) UIImageView *launchImageView;
- @property (nonatomic, strong) AVPlayer *player;
- @end
- @implementation StartFigureViewController
- /// 重写init方法,配置你想要的属性
- - (instancetype)init
- {
- self = [super init];
- if (self) {
-
- }
- return self;
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- // 隐藏导航条
- self.fd_prefersNavigationBarHidden = YES;
-
- /// 设置
- [self _setup];
-
- /// 设置导航栏
- [self _setupNavigationItem];
-
- /// 设置子控件
- [self _setupSubViews];
-
- /// 布局子空间
- [self _makeSubViewsConstraints];
-
- [self videoPlayCompleted];
- }
- - (void)viewDidDisappear:(BOOL)animated {
- [super viewDidDisappear:animated];
-
- // 删除监听
- [[NSNotificationCenter defaultCenter] removeObserver:self name:AVPlayerItemDidPlayToEndTimeNotification object:nil];
- [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidBecomeActiveNotification object:nil];
- }
- #pragma mark — Override
- - (void)bindViewModel {
-
- }
- #pragma mark - 事件处理Or辅助方法
- // 获取启动图
- - (UIImage *)getLaunchImage {
- UIImage *launchImage = nil;
- NSString *viewOrientation = nil;
- CGSize viewSize = [UIScreen mainScreen].bounds.size;
- UIInterfaceOrientation *orientation = [[UIApplication sharedApplication] userInterfaceLayoutDirection];
- if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) {
- viewOrientation = @"Landscape";
- }else {
- viewOrientation = @"Portrait";
- }
- NSArray *imagesDictionary = [[[NSBundle mainBundle] infoDictionary] valueForKey:@"UILaunchImages"];
- for (NSDictionary *dict in imagesDictionary) {
- CGSize imageSize = CGSizeFromString(dict[@"UILaunchImageSize"]);
- if (CGSizeEqualToSize(imageSize, viewSize) && [viewOrientation isEqualToString:dict[@"UILaunchImageOrientation"]]) {
- launchImage = [UIImage imageNamed:dict[@"UILaunchImageName"]];
- break;
- }
- }
- return launchImage;
- }
- - (void)videoPlayCompleted {
- if (self.videoPlaybackCompleted) {
- self.videoPlaybackCompleted();
- }
- }
- - (void)applicationDidBecomeActiveNotification {
- if (self.player) {
- [self.player play];
- }
- }
- #pragma mark - 初始化
- - (void)_setup{
- }
- #pragma mark - 设置导航栏
- - (void)_setupNavigationItem{
- }
- #pragma mark - 设置子控件
- - (void)_setupSubViews{
- // 显示封面
- UIImageView *launchImageView = [[UIImageView alloc] initWithFrame:SCREEN_BOUNDS];
- launchImageView.image = [self getLaunchImage];
- [self.view addSubview:launchImageView];
- return;
-
- // 播放视频
- NSURL *videoURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"xy_app_start" ofType:@"mp4"]];
- AVPlayer *player = [AVPlayer playerWithURL:videoURL];
- AVPlayerLayer *playerLayer = [AVPlayerLayer playerLayerWithPlayer:player];
- playerLayer.backgroundColor = Color_Clear.CGColor;
- playerLayer.frame = self.view.bounds;
- [self.view.layer addSublayer:playerLayer];
- [player play];
- self.player = player;
-
- // 添加监听
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(videoPlayCompleted) name:AVPlayerItemDidPlayToEndTimeNotification object:nil];
- // 在播放中进入后台会停止播放 再次进入前台需要继续播放
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidBecomeActiveNotification) name:UIApplicationDidBecomeActiveNotification object:nil];
- }
- #pragma mark - 布局子控件
- - (void)_makeSubViewsConstraints{
-
- }
- #pragma mark - Setter & Getter
- @end
|