From 027cf1ed55f88fa06d312751e4fb3477492f2b91 Mon Sep 17 00:00:00 2001 From: QuintGao <1094887059@qq.com> Date: Fri, 30 Apr 2021 16:30:04 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=A6=E6=83=85=E9=A1=B5=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E4=B8=BAGKPageSmoothView=EF=BC=8C=E5=A2=9E=E5=8A=A0=E5=AF=B9We?= =?UTF-8?q?bP=E5=8A=A8=E5=9B=BE=E7=9A=84=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- GKDYVideo/Classes/AppDelegate.m | 9 +++ .../Controller/GKDYListCollectionViewCell.h | 3 +- .../Controller/GKDYListCollectionViewCell.m | 9 ++- .../Home/Controller/GKDYListViewController.h | 5 +- .../Home/Controller/GKDYListViewController.m | 22 +----- .../Controller/GKDYPersonalViewController.m | 76 ++++++++----------- GKDYVideo/Classes/Home/View/GKDYHeaderView.m | 2 + GKDYVideo/Classes/Home/View/GKDYVideoView.m | 6 +- Podfile | 3 +- 9 files changed, 64 insertions(+), 71 deletions(-) diff --git a/GKDYVideo/Classes/AppDelegate.m b/GKDYVideo/Classes/AppDelegate.m index 9794fc6..95f9116 100644 --- a/GKDYVideo/Classes/AppDelegate.m +++ b/GKDYVideo/Classes/AppDelegate.m @@ -10,6 +10,8 @@ #import "GKDYHomeViewController.h" #import "GKDYShootViewController.h" #import "GKDYNavigationController.h" +#import +#import @interface AppDelegate () @@ -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; } diff --git a/GKDYVideo/Classes/Home/Controller/GKDYListCollectionViewCell.h b/GKDYVideo/Classes/Home/Controller/GKDYListCollectionViewCell.h index c57a15c..ef03f0c 100644 --- a/GKDYVideo/Classes/Home/Controller/GKDYListCollectionViewCell.h +++ b/GKDYVideo/Classes/Home/Controller/GKDYListCollectionViewCell.h @@ -8,6 +8,7 @@ #import #import "GKAWEModel.h" +#import NS_ASSUME_NONNULL_BEGIN @@ -15,7 +16,7 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, strong) GKAWEModel *model; -@property (nonatomic, strong) UIImageView *coverImgView; +@property (nonatomic, strong) SDAnimatedImageView *coverImgView; @end diff --git a/GKDYVideo/Classes/Home/Controller/GKDYListCollectionViewCell.m b/GKDYVideo/Classes/Home/Controller/GKDYListCollectionViewCell.m index 2e3dbc5..2a410e7 100644 --- a/GKDYVideo/Classes/Home/Controller/GKDYListCollectionViewCell.m +++ b/GKDYVideo/Classes/Home/Controller/GKDYListCollectionViewCell.m @@ -7,6 +7,7 @@ // #import "GKDYListCollectionViewCell.h" +#import "NSString+GKCategory.h" @interface GKDYListCollectionViewCell() @@ -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; } diff --git a/GKDYVideo/Classes/Home/Controller/GKDYListViewController.h b/GKDYVideo/Classes/Home/Controller/GKDYListViewController.h index c0884bf..34cd11c 100644 --- a/GKDYVideo/Classes/Home/Controller/GKDYListViewController.h +++ b/GKDYVideo/Classes/Home/Controller/GKDYListViewController.h @@ -7,17 +7,18 @@ // #import "GKDYBaseViewController.h" -#import +#import NS_ASSUME_NONNULL_BEGIN -@interface GKDYListViewController : GKDYBaseViewController +@interface GKDYListViewController : GKDYBaseViewController @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; diff --git a/GKDYVideo/Classes/Home/Controller/GKDYListViewController.m b/GKDYVideo/Classes/Home/Controller/GKDYListViewController.m index a9009fc..b6698fc 100644 --- a/GKDYVideo/Classes/Home/Controller/GKDYListViewController.m +++ b/GKDYVideo/Classes/Home/Controller/GKDYListViewController.m @@ -17,8 +17,6 @@ @interface GKDYListViewController () - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { + self.collectionView.mj_footer.hidden = self.videos.count == 0; return self.videos.count; } @@ -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; } @@ -143,10 +133,6 @@ - (UIScrollView *)listScrollView { return self.collectionView; } -- (void)listViewDidScrollCallback:(void (^)(UIScrollView *))callback { - self.scrollCallback = callback; -} - #pragma mark - 懒加载 - (UICollectionView *)collectionView { if (!_collectionView) { diff --git a/GKDYVideo/Classes/Home/Controller/GKDYPersonalViewController.m b/GKDYVideo/Classes/Home/Controller/GKDYPersonalViewController.m index a5e8acc..7db7410 100644 --- a/GKDYVideo/Classes/Home/Controller/GKDYPersonalViewController.m +++ b/GKDYVideo/Classes/Home/Controller/GKDYPersonalViewController.m @@ -9,7 +9,7 @@ #import "GKDYPersonalViewController.h" #import "GKNetworking.h" #import "GKDYPersonalModel.h" -#import +#import #import #import "GKDYHeaderView.h" #import "GKDYVideoViewController.h" @@ -18,9 +18,9 @@ #import "GKDYCommentView.h" #import "GKSlidePopupView.h" -@interface GKDYPersonalViewController () +@interface GKDYPersonalViewController () -@property (nonatomic, strong) GKPageScrollView *pageScrollView; +@property (nonatomic, strong) GKPageSmoothView *smoothView; @property (nonatomic, strong) GKDYHeaderView *headerView; @@ -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 { @@ -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)pageScrollView:(GKPageScrollView *)pageScrollView initListAtIndex:(NSInteger)index { +- (id)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 @@ -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 @@ -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 { @@ -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]; @@ -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); diff --git a/GKDYVideo/Classes/Home/View/GKDYHeaderView.m b/GKDYVideo/Classes/Home/View/GKDYHeaderView.m index 66d9b38..f233228 100644 --- a/GKDYVideo/Classes/Home/View/GKDYHeaderView.m +++ b/GKDYVideo/Classes/Home/View/GKDYHeaderView.m @@ -68,6 +68,8 @@ - (void)setModel:(GKAWEModel *)model { } - (void)scrollViewDidScroll:(CGFloat)offsetY { + NSLog(@"%f", offsetY); + CGRect frame = self.bgImgFrame; // 上下放大 frame.size.height -= offsetY; diff --git a/GKDYVideo/Classes/Home/View/GKDYVideoView.m b/GKDYVideo/Classes/Home/View/GKDYVideoView.m index ec29f13..afd4a2a 100644 --- a/GKDYVideo/Classes/Home/View/GKDYVideoView.m +++ b/GKDYVideo/Classes/Home/View/GKDYVideoView.m @@ -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; @@ -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) { @@ -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]; }]; diff --git a/Podfile b/Podfile index c999062..0919e76 100644 --- a/Podfile +++ b/Podfile @@ -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