视频启动页

#import "WDVedioVC.h"
#import <MediaPlayer/MediaPlayer.h>
#import <AVFoundation/AVFoundation.h>

#import "WDLoadFirstClass.h"
int lastindex = 0;

@interface WDVedioVC ()<UIScrollViewDelegate>{
    
    AVPlayer        *avPlayer;
    AVPlayerLayer   *avlayer;
    
}
@property (nonatomic,strong) UIScrollView *scroll;
@property (nonatomic,strong) UIButton *jumpBtn;
@end

@implementation WDVedioVC
@synthesize scroll = _scroll;

-(void)viewWillAppear:(BOOL)animated{
    
    self.navigationController.navigationBarHidden = YES;
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    UIImageView *bgImgView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, APP_WIDTH, APP_HEIGHT)];
    bgImgView.image = [UIImage imageNamed:@"vedioFristBgImg"];
    [self.view addSubview:bgImgView];
    
    self.automaticallyAdjustsScrollViewInsets = NO;
    _scroll = [[UIScrollView alloc]init];
    _scroll.backgroundColor = [UIColor whiteColor];
    _scroll.delegate = self;
    _scroll.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    _scroll.backgroundColor = [UIColor clearColor];
    _scroll.showsHorizontalScrollIndicator = NO;
    _scroll.showsVerticalScrollIndicator = NO;
    _scroll.pagingEnabled = YES;
    _scroll.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
    _scroll.contentSize = CGSizeMake((self.view.frame.size.width), _scroll.frame.size.height);
    _scroll.bounces = NO;
    [self.view addSubview:_scroll];
    
    [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback withOptions:AVAudioSessionCategoryOptionMixWithOthers error:nil];
    NSURL *urlMovie1 = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"5m" ofType:@"mp4"]];
    AVURLAsset *asset1 = [AVURLAsset URLAssetWithURL:urlMovie1 options:nil];
    AVPlayerItem *playerItem1 = [AVPlayerItem playerItemWithAsset:asset1];
    avPlayer = [AVPlayer playerWithPlayerItem: playerItem1];
    avlayer = [AVPlayerLayer playerLayerWithPlayer:avPlayer];
    avlayer.frame = (CGRect){0, 0, self.view.frame.size.width, self.view.frame.size.height};
    avlayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
    [_scroll.layer addSublayer:avlayer];
    
    [avPlayer play];
    
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(playbackFinished:)
                                                 name:AVPlayerItemDidPlayToEndTimeNotification
                                               object:avPlayer.currentItem];
    
    
    _jumpBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _jumpBtn.backgroundColor = [UIColor clearColor];
    _jumpBtn.frame = CGRectMake(APP_WIDTH-45 -20, 45-20, 40, 40);
    _jumpBtn.titleLabel.font = [UIFont systemFontOfSize:14.f];
    [_jumpBtn setTitle:@"跳过" forState:UIControlStateNormal];
    [_jumpBtn addTarget:self action:@selector(jumpToFinished) forControlEvents:UIControlEventTouchUpInside];
    _jumpBtn.enabled = NO;
    [self.view addSubview:_jumpBtn];
    
    [self setUpAnimationLayer];
    [self performSelector:@selector(dismiss) withObject:nil afterDelay:5.0f];
    
}


-(void)dismiss{
    [UIView animateWithDuration:0.5 animations:^{
        
    } completion:^(BOOL finished) {
        _jumpBtn.enabled = YES;
    }];
}

-(void)jumpToFinished{
    WDLog(@"跳过");
    [[NSUserDefaults standardUserDefaults] setObject:@"1" forKey:@"appFirstBoot"];
    [[NSUserDefaults standardUserDefaults] synchronize];
    [WDLoadFirstClass loadRootControl];
}

- (void)playbackFinished:(NSNotification *)noti{
    WDLog(@"视频放完了");
    [[NSUserDefaults standardUserDefaults] setObject:@"1" forKey:@"appFirstBoot"];
    [[NSUserDefaults standardUserDefaults] synchronize];
    
    [WDLoadFirstClass loadRootControl];
}

//倒计时的圈圈
-(void)setUpAnimationLayer{
    //因为会多次点击,所以要将该图层移除,并且指针置空
    [self.animationLayer removeFromSuperlayer];
    self.animationLayer = nil;
    
    UIBezierPath * path = [UIBezierPath bezierPath];
    //参数依次是:圆心坐标,半径,开始弧度,结束弧度   画线方向:yes为顺时针,no为逆时针
    [path addArcWithCenter:CGPointMake(APP_WIDTH-45, 45) radius:20 startAngle:-M_PI_2 endAngle:2*M_PI-M_PI_2 clockwise:TRUE];
    CAShapeLayer * pathLayer = [CAShapeLayer layer];
    pathLayer.path = path.CGPath;
    pathLayer.strokeColor = [[[UIColor whiteColor] colorWithAlphaComponent:0.7] CGColor];//画线颜色
    pathLayer.fillColor = [[UIColor clearColor] CGColor];//填充颜色
    pathLayer.lineJoin = kCALineJoinRound;
    pathLayer.lineWidth = 4.0f;
    [_scroll.layer addSublayer:pathLayer];
    self.animationLayer = pathLayer;//把pathLayer赋给属性animationLayer
    
    //动画
    [self.animationLayer removeAllAnimations];//每次将之前的动画都清除了
    //keyPath = strokeEnd  动画的fromValue = 0,toValue = 1表示 这里我们分3个点说明动画的顺序  strokeEnd从结尾开始清除 首先整条路径先清除后2/3,接着清除1/3 效果就是正方向画出路径
    
    CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
    pathAnimation.duration = 5.0;
    pathAnimation.fromValue = @(0);
    pathAnimation.toValue = @(1);
    [self.animationLayer addAnimation:pathAnimation forKey:@"strokeEnd"];
}



- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
        [avPlayer seekToTime:kCMTimeZero];
        [avPlayer play];
}

- (void)dealloc{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}



@end

 #import <UIKit/UIKit.h>

@interface WDVedioVC : UIViewController

@property(nonatomic, strong)CAShapeLayer *animationLayer;

@end 

原文地址:https://www.cnblogs.com/-yun/p/7884123.html