Skip to content

Commit

Permalink
详情页修改为GKPageSmoothView,增加对WebP动图的支持
Browse files Browse the repository at this point in the history
  • Loading branch information
QuintGao committed Apr 30, 2021
1 parent d5a0403 commit 027cf1e
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 71 deletions.
9 changes: 9 additions & 0 deletions GKDYVideo/Classes/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#import "GKDYHomeViewController.h"
#import "GKDYShootViewController.h"
#import "GKDYNavigationController.h"
#import <SDWebImage/SDWebImage.h>
#import <SDWebImageWebPCoder/SDWebImageWebPCoder.h>

@interface AppDelegate ()

Expand Down Expand Up @@ -48,6 +50,13 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
self.window.rootViewController = nav;
[self.window makeKeyAndVisible];

// Add WebPCoder
SDImageWebPCoder *webPCoder = [SDImageWebPCoder sharedCoder];
[[SDImageCodersManager sharedManager] addCoder:webPCoder];

// Modify HTTP Accept Header
[[SDWebImageDownloader sharedDownloader] setValue:@"image/webp,image/*,*/*;q=0.8" forHTTPHeaderField:@"Accept"];

return YES;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@

#import <UIKit/UIKit.h>
#import "GKAWEModel.h"
#import <SDWebImage/SDAnimatedImageView.h>

NS_ASSUME_NONNULL_BEGIN

@interface GKDYListCollectionViewCell : UICollectionViewCell

@property (nonatomic, strong) GKAWEModel *model;

@property (nonatomic, strong) UIImageView *coverImgView;
@property (nonatomic, strong) SDAnimatedImageView *coverImgView;

@end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

#import "GKDYListCollectionViewCell.h"
#import "NSString+GKCategory.h"

@interface GKDYListCollectionViewCell()

Expand Down Expand Up @@ -36,15 +37,15 @@ - (instancetype)initWithFrame:(CGRect)frame {
- (void)setModel:(GKAWEModel *)model {
_model = model;

[self.coverImgView sd_setImageWithURL:[NSURL URLWithString:model.video.cover.url_list.firstObject]];
[self.coverImgView sd_setImageWithURL:[NSURL URLWithString:model.video.dynamic_cover.url_list.firstObject]];

[self.starBtn setTitle:model.statistics.digg_count forState:UIControlStateNormal];
[self.starBtn setTitle:[model.statistics.digg_count gk_unitConvert] forState:UIControlStateNormal];
}

#pragma mark - 懒加载
- (UIImageView *)coverImgView {
- (SDAnimatedImageView *)coverImgView {
if (!_coverImgView) {
_coverImgView = [UIImageView new];
_coverImgView = [SDAnimatedImageView new];
_coverImgView.contentMode = UIViewContentModeScaleAspectFill;
_coverImgView.clipsToBounds = YES;
}
Expand Down
5 changes: 3 additions & 2 deletions GKDYVideo/Classes/Home/Controller/GKDYListViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@
//

#import "GKDYBaseViewController.h"
#import <GKPageScrollView/GKPageScrollView.h>
#import <GKPageSmoothView/GKPageSmoothView.h>

NS_ASSUME_NONNULL_BEGIN

@interface GKDYListViewController : GKDYBaseViewController<GKPageListViewDelegate>
@interface GKDYListViewController : GKDYBaseViewController<GKPageSmoothListViewDelegate>

@property (nonatomic, strong) UICollectionView *collectionView;

@property (nonatomic, assign) NSInteger selectedIndex;

@property (nonatomic, copy) void(^itemClickBlock)(NSArray *videos, NSInteger index);
@property (nonatomic, copy) void(^refreshBlock)(void);

- (void)refreshData;

Expand Down
22 changes: 4 additions & 18 deletions GKDYVideo/Classes/Home/Controller/GKDYListViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ @interface GKDYListViewController ()<UICollectionViewDataSource, UICollectionVie

@property (nonatomic, strong) NSMutableArray *videos;

@property (nonatomic, copy) void(^scrollCallback)(UIScrollView *scrollView);

@property (nonatomic, assign) BOOL isRefresh;
@property (nonatomic, assign) NSInteger index;

Expand Down Expand Up @@ -65,7 +63,7 @@ - (void)viewDidLoad {
[self.collectionView.mj_footer endRefreshing];
}];

[self.view addSubview:self.loadingBgView];
[self.collectionView addSubview:self.loadingBgView];
self.loadingBgView.frame = CGRectMake(0, 0, SCREEN_WIDTH, ADAPTATIONRATIO * 400.0f);

// 模拟数据加载
Expand Down Expand Up @@ -98,7 +96,7 @@ - (void)viewDidLoad {
[self.videos addObjectsFromArray:array];

[self.collectionView.mj_header endRefreshing];

!self.refreshBlock ? : self.refreshBlock();
[self.collectionView reloadData];
});
}
Expand All @@ -111,6 +109,7 @@ - (void)refreshData {

#pragma mark - <UICollectionViewDataSource, UICollectionViewDelegate>
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
self.collectionView.mj_footer.hidden = self.videos.count == 0;
return self.videos.count;
}

Expand All @@ -122,19 +121,10 @@ - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cell

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
self.selectedIndex = indexPath.item;

// GKDYVideoViewController *playerVC = [[GKDYVideoViewController alloc] initWithVideos:self.videos index:indexPath.item];
// [self.navigationController pushViewController:playerVC animated:YES];

!self.itemClickBlock ? : self.itemClickBlock(self.videos, indexPath.item);
}

#pragma mark - UIScrollViewDelegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
!self.scrollCallback ? : self.scrollCallback(scrollView);
}

#pragma mark - GKPageListViewDelegate
#pragma mark - GKPageSmoothListViewDelegate
- (UIView *)listView {
return self.view;
}
Expand All @@ -143,10 +133,6 @@ - (UIScrollView *)listScrollView {
return self.collectionView;
}

- (void)listViewDidScrollCallback:(void (^)(UIScrollView *))callback {
self.scrollCallback = callback;
}

#pragma mark - 懒加载
- (UICollectionView *)collectionView {
if (!_collectionView) {
Expand Down
76 changes: 32 additions & 44 deletions GKDYVideo/Classes/Home/Controller/GKDYPersonalViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#import "GKDYPersonalViewController.h"
#import "GKNetworking.h"
#import "GKDYPersonalModel.h"
#import <GKPageScrollView/GKPageScrollView.h>
#import <GKPageSmoothView/GKPageSmoothView.h>
#import <JXCategoryView/JXCategoryView.h>
#import "GKDYHeaderView.h"
#import "GKDYVideoViewController.h"
Expand All @@ -18,9 +18,9 @@
#import "GKDYCommentView.h"
#import "GKSlidePopupView.h"

@interface GKDYPersonalViewController ()<GKPageScrollViewDelegate, GKPageTableViewGestureDelegate, JXCategoryViewDelegate, UIScrollViewDelegate, GKDYVideoViewDelegate>
@interface GKDYPersonalViewController ()<GKPageSmoothViewDataSource, GKPageSmoothViewDelegate, JXCategoryViewDelegate, UIScrollViewDelegate, GKDYVideoViewDelegate>

@property (nonatomic, strong) GKPageScrollView *pageScrollView;
@property (nonatomic, strong) GKPageSmoothView *smoothView;

@property (nonatomic, strong) GKDYHeaderView *headerView;

Expand All @@ -41,21 +41,20 @@ @implementation GKDYPersonalViewController
- (void)viewDidLoad {
[super viewDidLoad];


self.gk_navBackgroundColor = GKColorRGB(34, 33, 37);
self.gk_navTitleView = self.titleView;
self.gk_statusBarStyle = UIStatusBarStyleLightContent;
self.gk_navLineHidden = YES;
self.gk_navBarAlpha = 0;

[self.view addSubview:self.pageScrollView];
[self.pageScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
[self.view addSubview:self.smoothView];
[self.smoothView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.view);
}];

self.categoryView.contentScrollView = self.smoothView.listCollectionView;
self.headerView.model = self.model;

[self.pageScrollView reloadData];
[self.smoothView reloadData];
}

- (void)viewWillAppear:(BOOL)animated {
Expand Down Expand Up @@ -89,39 +88,39 @@ - (void)showVideoVCWithVideos:(NSArray *)videos index:(NSInteger)index {
self.scaleView = scaleView;
}

#pragma mark - GKPageScrollViewDelegate
- (BOOL)shouldLazyLoadListInPageScrollView:(GKPageScrollView *)pageScrollView {
return YES;
}

- (UIView *)headerViewInPageScrollView:(GKPageScrollView *)pageScrollView {
#pragma mark - GKPageSmoothViewDataSource
- (UIView *)headerViewInSmoothView:(GKPageSmoothView *)smoothView {
return self.headerView;
}

- (UIView *)segmentedViewInPageScrollView:(GKPageScrollView *)pageScrollView {
- (UIView *)segmentedViewInSmoothView:(GKPageSmoothView *)smoothView {
return self.categoryView;
}

- (NSInteger)numberOfListsInPageScrollView:(GKPageScrollView *)pageScrollView {
return self.titles.count;
- (NSInteger)numberOfListsInSmoothView:(GKPageSmoothView *)smoothView {
return self.categoryView.titles.count;
}

- (id<GKPageListViewDelegate>)pageScrollView:(GKPageScrollView *)pageScrollView initListAtIndex:(NSInteger)index {
- (id<GKPageSmoothListViewDelegate>)smoothView:(GKPageSmoothView *)smoothView initListAtIndex:(NSInteger)index {
GKDYListViewController *listVC = [GKDYListViewController new];

@weakify(self);
listVC.itemClickBlock = ^(NSArray * _Nonnull videos, NSInteger index) {
@strongify(self);
[self showVideoVCWithVideos:videos index:index];
};

listVC.refreshBlock = ^{
[smoothView scrollToOriginalPoint];
};

[self addChildViewController:listVC];
return listVC;
}

- (void)mainTableViewDidScroll:(UIScrollView *)scrollView isMainCanScroll:(BOOL)isMainCanScroll {
#pragma mark - GKPageSmoothViewDelegate
- (void)smoothView:(GKPageSmoothView *)smoothView listScrollViewDidScroll:(UIScrollView *)scrollView contentOffset:(CGPoint)contentOffset {
// 导航栏显隐
CGFloat offsetY = scrollView.contentOffset.y;
CGFloat offsetY = contentOffset.y;
// 0-100 0
// 100 - KDYHeaderHeigh - kNavBarheight 渐变从0-1
// > KDYHeaderHeigh - kNavBarheight 1
Expand All @@ -133,25 +132,18 @@ - (void)mainTableViewDidScroll:(UIScrollView *)scrollView isMainCanScroll:(BOOL)
}else {
alpha = (offsetY - 60) / (kDYHeaderHeight - NAVBAR_HEIGHT - 60);
}
NSLog(@"%f", alpha);
self.gk_navBarAlpha = alpha;
self.titleView.alpha = alpha;

if (offsetY > smoothView.headerContainerHeight) {
return;
}
[self.headerView scrollViewDidScroll:offsetY];
}

#pragma mark - JXCategoryViewDelegate
- (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index {
self.currentListVC = (GKDYListViewController *)self.pageScrollView.validListDict[@(index)];
}

#pragma mark - UIScrollViewDelegate
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
[self.pageScrollView horizonScrollViewWillBeginScroll];
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
[self.pageScrollView horizonScrollViewDidEndedScroll];
self.currentListVC = (GKDYListViewController *)self.smoothView.listDict[@(index)];
}

#pragma mark - GKDYVideoViewDelegate
Expand All @@ -172,22 +164,20 @@ - (void)videoView:(GKDYVideoView *)videoView didClickComment:(GKAWEModel *)video
}

#pragma mark - GKPageTableViewGestureDelegate
- (BOOL)pageTableView:(GKPageTableView *)tableView gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
return YES;
}

- (BOOL)prefersStatusBarHidden {
[self refreshNavBarFrame];
return self.gk_statusBarHidden;
}

#pragma mark - 懒加载
- (GKPageScrollView *)pageScrollView {
if (!_pageScrollView) {
_pageScrollView = [[GKPageScrollView alloc] initWithDelegate:self];
_pageScrollView.mainTableView.gestureDelegate = self;
- (GKPageSmoothView *)smoothView {
if (!_smoothView) {
_smoothView = [[GKPageSmoothView alloc] initWithDataSource:self];
_smoothView.delegate = self;
_smoothView.ceilPointHeight = GK_STATUSBAR_NAVBAR_HEIGHT;
_smoothView.listCollectionView.gk_openGestureHandle = YES;
}
return _pageScrollView;
return _smoothView;
}

- (GKDYHeaderView *)headerView {
Expand All @@ -212,7 +202,7 @@ - (JXCategoryTitleView *)categoryView {
if (!_categoryView) {
_categoryView = [[JXCategoryTitleView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 40.0f)];
_categoryView.backgroundColor = GKColorRGB(34, 33, 37);
_categoryView.titles = self.titles;
_categoryView.titles = @[@"作品 129", @"动态 129", @"喜欢 591"];
_categoryView.delegate = self;
_categoryView.titleColor = [UIColor grayColor];
_categoryView.titleSelectedColor = [UIColor whiteColor];
Expand All @@ -226,8 +216,6 @@ - (JXCategoryTitleView *)categoryView {
lineView.lineStyle = JXCategoryIndicatorLineStyle_Normal;
_categoryView.indicators = @[lineView];

_categoryView.contentScrollView = self.pageScrollView.listContainerView.collectionView;

// 添加分割线
UIView *btmLineView = [UIView new];
btmLineView.frame = CGRectMake(0, 40 - 0.5, SCREEN_WIDTH, 0.5);
Expand Down
2 changes: 2 additions & 0 deletions GKDYVideo/Classes/Home/View/GKDYHeaderView.m
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ - (void)setModel:(GKAWEModel *)model {
}

- (void)scrollViewDidScroll:(CGFloat)offsetY {
NSLog(@"%f", offsetY);

CGRect frame = self.bgImgFrame;
// 上下放大
frame.size.height -= offsetY;
Expand Down
6 changes: 5 additions & 1 deletion GKDYVideo/Classes/Home/View/GKDYVideoView.m
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,12 @@ - (instancetype)initWithVC:(UIViewController *)vc isPushed:(BOOL)isPushed {
[self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self);
}];

isPushed = YES;
// 不是push过来的,添加下拉刷新
if (!isPushed) {
@weakify(self);
self.scrollView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
@strongify(self);
if (self.isRefreshMore) return;
self.isRefreshMore = YES;

Expand All @@ -74,6 +76,7 @@ - (instancetype)initWithVC:(UIViewController *)vc isPushed:(BOOL)isPushed {
self.currentPlayIndex = self.videos.count - 1;

[self.viewModel refreshMoreListWithSuccess:^(NSArray * _Nonnull list) {
@strongify(self);
self.isRefreshMore = NO;

if (list) {
Expand All @@ -89,6 +92,7 @@ - (instancetype)initWithVC:(UIViewController *)vc isPushed:(BOOL)isPushed {

self.scrollView.contentOffset = CGPointMake(0, 2 * SCREEN_HEIGHT);
} failure:^(NSError * _Nonnull error) {
@strongify(self);
self.isRefreshMore = NO;
[self.scrollView.mj_footer endRefreshingWithNoMoreData];
}];
Expand Down
3 changes: 2 additions & 1 deletion Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ target 'GKDYVideo' do

pod 'AFNetworking'
pod 'SDWebImage'
pod 'SDWebImageWebPCoder'
pod 'Masonry'
pod 'YYModel'
pod 'GKNavigationBar'
pod 'TXLiteAVSDK_Player' # 腾讯云播放器-独立播放器
pod 'MJRefresh'
pod 'GKPageScrollView'
pod 'GKPageSmoothView'
pod 'JXCategoryView'

end
Expand Down

0 comments on commit 027cf1e

Please sign in to comment.