//
// ODVideoDetailController.m
// oudaBuyer
//
// Created by lixiang on 2016/11/22.
// Copyright © 2016年 ouda. All rights reserved.
//
#import “ODVideoDetailController.h”
#import “LEOHeaderView.h”
#import “ODShopSpecialSingleListCell.h”
@interface ODVideoDetailController ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) LEOHeaderView *headerView;
@property (nonatomic, assign) CGFloat smallWH;//播放器最小的时候的宽度 高度
@end
@implementation ODVideoDetailController
– (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.navigationController.navigationBar.hidden = YES;
[self.headerView reloadWithScrollView:self.tableView];
}
– (void)viewDidLoad {
[super viewDidLoad];
if (kWidthOfScreen == 320) {
self.smallWH = 100;
}else if (kWidthOfScreen == 375){
self.smallWH = 146;
}else if (kWidthOfScreen == 414){
self.smallWH = 174;
}
self.view.backgroundColor = [UIColor whiteColor];
self.automaticallyAdjustsScrollViewInsets = NO;
self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, self.smallWH, kWidthOfScreen, kHeightOfScreen – self.smallWH)];
self.tableView.dataSource = self;
self.tableView.delegate = self;
self.tableView.showsVerticalScrollIndicator = NO;
self.tableView.contentInset = UIEdgeInsetsMake(kWidthOfScreen – self.smallWH, 0, 0, 0);
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
self.tableView.backgroundColor = [UIColor clearColor];
[self.view addSubview:self.tableView];
self.headerView = [[LEOHeaderView alloc] initWithFrame:CGRectMake(0, 0, kWidthOfScreen, kWidthOfScreen) andVideoUrl:[NSURL URLWithString:self.model.videoInfo.path] andWH:self.smallWH];
self.headerView.tableView = self.tableView;
[self.view addSubview:self.headerView];
}
– (void)scrollViewDidScroll:(UIScrollView *)scrollView {
[self.headerView reloadWithScrollView:scrollView];
}
// 有可能成为最终滚动的位置
– (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
if (scrollView.contentOffset.y > 0) {
[self.headerView confirmSmall];
}
if (scrollView.contentOffset.y == –kWidthOfScreen+self.smallWH){
[self.headerView confirmBig];
}
}
– (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 2+self.model.goodsList.count;
}
– (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == 0) {
ODSpecialVideoDetailCell *cell = [ODSpecialVideoDetailCell cellWithTableView:tableView];
cell.model = self.model;
return cell;
}
if (indexPath.row == 1) {
UITableViewCell *cell = [UITableViewCell new];
cell.textLabel.text = @” 视频内商品信息“;
cell.textLabel.textColor = ODBlackColor;
cell.textLabel.font = [UIFont systemFontOfSize:14 weight:UIFontWeightMedium];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
UIView *line1 = [[UIView alloc]initWithFrame:CGRectMake(15, 14.75, 9, 0.5)];
line1.backgroundColor = ODFontGrayColor;
[cell.contentView insertSubview:line1 belowSubview:cell.textLabel];
UIView *line2 = [[UIView alloc]initWithFrame:CGRectMake(135, 14.75, kWidthOfScreen–160, 0.5)];
line2.backgroundColor = ODFontGrayColor;
[cell.contentView addSubview:line2];
return cell;
}
ODShopSpecialSingleListCell *cell = [ODShopSpecialSingleListCell cellWithTableView:tableView];
cell.model2 = self.model.goodsList[indexPath.row–2];
return cell;
}
– (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == 0) {
return 115+[self.model.videoInfo.desc getLabelHeightWithFont:[UIFont systemFontOfSize:14 weight:UIFontWeightLight] withLineSpacing:6 maxSize:CGSizeMake(kWidthOfScreen–30, MAXFLOAT)];
}
if (indexPath.row == 1) {
return 30;
}
return 120;
}
@end
#import “LEOHeaderView.h”
@interface LEOHeaderView ()<VIMVideoPlayerViewDelegate>
@property (nonatomic, assign) CGFloat smallWH;//播放器最小的时候的宽度 高度
@end
@implementation LEOHeaderView
– (instancetype)initWithFrame:(CGRect)frame andVideoUrl:(NSURL *)url andWH:(CGFloat)wh{
if (self = [super initWithFrame:frame]) {
self.smallWH = wh;
self.playerView = [[VIMVideoPlayerView alloc]init];
self.player = [[VIMVideoPlayer alloc]init];
[self.playerView setPlayer:self.player];
[self.playerView.player setURL:url];
self.playerView.backgroundColor = [UIColor blackColor];
self.playerView.size = CGSizeMake(kWidthOfScreen, kWidthOfScreen);
self.playerView.center = CGPointMake(kWidthOfScreen/2, kWidthOfScreen/2);
[self addSubview:self.playerView];
self.playerView.delegate = self;
[self.player play];
}
return self;
}
– (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
UIView *hitView = [super hitTest:point withEvent:event];
CGPoint cPoint = [self convertPoint:point toView:self.playerView];
if ([self.playerView.layer containsPoint:cPoint]) {
return hitView;
}else{
return self.tableView;
}
}
– (void)reloadWithScrollView:(UIScrollView *)scrollView {
CGFloat offsetY = scrollView.contentOffset.y + kWidthOfScreen – self.smallWH;
if (offsetY < 0) {
} else if (offsetY > 0 && offsetY <= kWidthOfScreen – self.smallWH) {
self.top = -offsetY / 2;
CGFloat kEachPixel = (1 – self.smallWH / kWidthOfScreen) / (kWidthOfScreen – self.smallWH);
CGFloat kScale = 1 – offsetY * kEachPixel;
self.playerView.frame = CGRectMake(0, offsetY / 2, kWidthOfScreen, kWidthOfScreen*kScale);
}
}
– (void)confirmSmall {
[UIView animateWithDuration:0.3 animations:^{
self.top = –self.smallWH;
self.playerView.frame = CGRectMake(0, self.smallWH, kWidthOfScreen, self.smallWH);
}];
}
– (void)confirmBig {
[UIView animateWithDuration:0.3 animations:^{
self.top = 0;
self.playerView.frame = CGRectMake(0, 0, kWidthOfScreen, kWidthOfScreen);
}];
}
– (void)videoPlayerViewDidReachEnd:(VIMVideoPlayerView *)videoPlayerView {
[self.player.player seekToTime:kCMTimeZero];
}
@end