Skip to content

Commit

Permalink
优化代码,修复bug #78
Browse files Browse the repository at this point in the history
  • Loading branch information
QuintGao committed Sep 27, 2021
1 parent d861bb6 commit 025653c
Show file tree
Hide file tree
Showing 15 changed files with 66 additions and 45 deletions.
2 changes: 1 addition & 1 deletion GKPageScrollView.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'GKPageScrollView'
s.version = '1.6.4'
s.version = '1.6.5'
s.summary = 'iOS UIScrollView嵌套滑动分页视图'
s.homepage = 'https://github.com/QuintGao/GKPageScrollView'
s.license = { :type => "MIT", :file => "LICENSE" }
Expand Down
2 changes: 1 addition & 1 deletion GKPageSmoothView.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'GKPageSmoothView'
s.version = '1.6.4'
s.version = '1.6.5'
s.summary = 'iOS UIScrollView嵌套滑动分页视图'
s.homepage = 'https://github.com/QuintGao/GKPageScrollView'
s.license = { :type => "MIT", :file => "LICENSE" }
Expand Down
2 changes: 1 addition & 1 deletion ObjcExample/ObjcExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@
isa = PBXProject;
attributes = {
DefaultBuildSystemTypeForWorkspace = Latest;
LastUpgradeCheck = 1230;
LastUpgradeCheck = 1300;
TargetAttributes = {
609B8DE3259AFC6E000F1EB9 = {
CreatedOnToolsVersion = 12.3;
Expand Down
10 changes: 10 additions & 0 deletions ObjcExample/ObjcExample/Demo/Base/GKBaseListViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ @implementation GKBaseListViewController
- (instancetype)initWithListType:(GKBaseListType)listType {
if (self = [super init]) {
self.listType = listType;

if (self.listType == GKBaseListType_UITableView) {
self.currentScrollView = self.tableView;
}else if (self.listType == GKBaseListType_UICollectionView) {
self.currentScrollView = self.collectionView;
}else if (self.listType == GKBaseListType_UIScrollView) {
self.currentScrollView = self.scrollView;
}else if (self.listType == GKBaseListType_WKWebView) {
self.currentScrollView = self.webView.scrollView;
}
}
return self;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#import "GKBaseListViewController.h"
#import <MJRefresh/MJRefresh.h>
#import "GKSmoothListViewController.h"
#import "GKBaseListViewController.h"

@interface GKSmoothViewController ()<GKPageSmoothViewDataSource, GKPageSmoothViewDelegate, GKSmoothListViewDelegate, GKSmoothListViewControllerDelegate>

Expand Down Expand Up @@ -68,13 +69,16 @@ - (NSInteger)numberOfListsInSmoothView:(GKPageSmoothView *)smoothView {
}

- (id<GKPageSmoothListViewDelegate>)smoothView:(GKPageSmoothView *)smoothView initListAtIndex:(NSInteger)index {
GKSmoothListView *listView = [[GKSmoothListView alloc] initWithListType:GKSmoothListType_TableView deleagte:self index:index];
[listView requestData];
return listView;
// GKSmoothListView *listView = [[GKSmoothListView alloc] initWithListType:GKSmoothListType_TableView deleagte:self index:index];
// [listView requestData];
// return listView;
// GKSmoothListViewController *listVC = [GKSmoothListViewController new];
// listVC.delegate = self;
// listVC.index = index;
// return listVC;
GKBaseListViewController *listVC = [[GKBaseListViewController alloc] initWithListType:index];
listVC.shouldLoadData = YES;
return listVC;
}

#pragma mark - GKPageSmoothViewDelegate
Expand Down Expand Up @@ -109,7 +113,7 @@ - (GKPageSmoothView *)smoothView {
_smoothView.delegate = self;
_smoothView.listCollectionView.gk_openGestureHandle = YES;
// _smoothView.mainScrollDisabled = YES;
// _smoothView.holdUpScrollView = YES;
_smoothView.holdUpScrollView = YES;
}
return _smoothView;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#import "GKDBViewController.h"
#import "GKPageSmoothView.h"
#import "GKDBListView.h"
#import "GKBaseListViewController.h"
#import "GKSmoothListViewController.h"

@interface GKDBViewController ()<GKPageSmoothViewDataSource, GKPageSmoothViewDelegate, JXCategoryViewDelegate>

Expand Down Expand Up @@ -148,6 +150,7 @@ - (GKPageSmoothView *)smoothView {
_smoothView.allowDragScroll = YES;
// 解决与返回手势滑动冲突
_smoothView.listCollectionView.gk_openGestureHandle = YES;
_smoothView.holdUpScrollView = YES;
}
return _smoothView;
}
Expand Down
19 changes: 5 additions & 14 deletions Pods/Pods.xcodeproj/project.pbxproj

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Sources/GKPageScrollView/GKPageScrollView.m
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ - (void)initSubviews {
if (@available(iOS 11.0, *)) {
self.mainTableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
}
if (@available(iOS 15.0, *)) {
self.mainTableView.sectionHeaderTopPadding = 0;
}
[self addSubview:self.mainTableView];
[self refreshHeaderView];

Expand Down
13 changes: 0 additions & 13 deletions Sources/GKPageScrollView/GKPageTableView.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,6 @@ - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecogni
if (exist) return NO;
}

// // 特殊处理,解决GKPageTableView上下滑动与返回手势左右滑动冲突
// NSArray *internalTargets = [otherGestureRecognizer valueForKey:@"targets"];
// id internalTarget = [internalTargets.firstObject valueForKey:@"target"];
// if ([internalTargets isKindOfClass:[NSClassFromString(@"_UINavigationInteractiveTransition")]]) {
// return NO;
// }


// // 特殊处理,解决返回手势与GKPageTableView手势的冲突
// NSArray *internalTargets = [otherGestureRecognizer valueForKey:@"targets"];
// id internalTarget = [internalTargets.firstObject valueForKey:@"target"];
// if ([internalTarget isKindOfClass:NSClassFromString(@"_UINavigationInteractiveTransition")]) return NO;

return [gestureRecognizer.view isKindOfClass:[UIScrollView class]] && [otherGestureRecognizer.view isKindOfClass:[UIScrollView class]];
}

Expand Down
3 changes: 3 additions & 0 deletions Sources/GKPageScrollViewSwift/GKPageScrollView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,9 @@ open class GKPageScrollView: UIView {
if #available(iOS 11.0, *) {
self.mainTableView.contentInsetAdjustmentBehavior = .never
}
if #available(iOS 15.0, *) {
self.mainTableView.sectionHeaderTopPadding = 0
}
self.addSubview(mainTableView)
self.refreshHeaderView()

Expand Down
19 changes: 14 additions & 5 deletions Sources/GKPageSmoothView/GKPageSmoothView.m
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ @interface GKPageSmoothView()<UICollectionViewDataSource, UICollectionViewDelega
@property (nonatomic, assign) BOOL originBounces;
@property (nonatomic, assign) BOOL originShowsVerticalScrollIndicator;

@property (nonatomic, assign) BOOL isScroll;

@end

@implementation GKPageSmoothView
Expand Down Expand Up @@ -308,17 +310,17 @@ - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
}

NSInteger index = scrollView.contentOffset.x / scrollView.bounds.size.width;

NSInteger ratio = (int)scrollView.contentOffset.x % (int)scrollView.bounds.size.width;
self.isScroll = YES;

if (!self.isMainScrollDisabled) {
if (!self.isOnTop) {
UIScrollView *listScrollView = self.listDict[@(index)].listScrollView;
if (index != self.currentIndex && ratio == 0 && !(scrollView.isDragging || scrollView.isDecelerating) && listScrollView.contentOffset.y <= -(self.segmentedHeight + self.ceilPointHeight)) {
if (index != self.currentIndex && ratio == 0 && !(scrollView.isTracking || scrollView.isDecelerating) && listScrollView.contentOffset.y <= -(self.segmentedHeight + self.ceilPointHeight)) {
[self horizontalScrollDidEndAtIndex:index];
}else {
// 左右滚动的时候,把headerContainerView添加到self,达到悬浮的效果
if (self.headerContainerView.superview != self) {
if (self.headerContainerView.superview != self && ratio != 0) {
CGRect frame = self.headerContainerView.frame;
frame.origin.y = self.currentHeaderContainerViewY;
self.headerContainerView.frame = frame;
Expand Down Expand Up @@ -351,8 +353,15 @@ - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {

- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView {
// 修复快速闪烁问题
self.currentIndex = scrollView.contentOffset.x / scrollView.bounds.size.width;
self.currentListScrollView = self.listDict[@(self.currentIndex)].listScrollView;
NSInteger index = scrollView.contentOffset.x / scrollView.bounds.size.width;
self.currentIndex = index;
self.currentListScrollView = self.listDict[@(index)].listScrollView;
self.isScroll = NO;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.15 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
if (!self.isScroll && self.headerContainerView.superview == self) {
[self horizontalScrollDidEndAtIndex:index];
}
});
}

#pragma mark - KVO
Expand Down
Loading

0 comments on commit 025653c

Please sign in to comment.