Skip to content

Commit

Permalink
fix: cancel intercept scroll view delegate when the view is animating
Browse files Browse the repository at this point in the history
  • Loading branch information
tigerAndBull committed Dec 31, 2021
1 parent 7066fba commit 0c54a44
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 20 deletions.
14 changes: 0 additions & 14 deletions TABAnimatedDemo/TABAnimated/Control/TABFormAnimated.m
Original file line number Diff line number Diff line change
Expand Up @@ -375,15 +375,13 @@ - (BOOL)scrollEnabled {

- (void)tab_scrollViewDidScroll:(UIScrollView *)scrollView {
TABFormAnimated *tabAnimated = (TABFormAnimated *)(scrollView.tabAnimated);
if (tabAnimated.isAnimating) return;
id oldDelegate = tabAnimated.oldDelegate;
SEL sel = @selector(scrollViewDidScroll:);
((void (*)(id, SEL, UIScrollView *))objc_msgSend)((id)oldDelegate, sel, scrollView);
}

- (void)tab_scrollViewDidZoom:(UIScrollView *)scrollView {
TABFormAnimated *tabAnimated = (TABFormAnimated *)(scrollView.tabAnimated);
if (tabAnimated.isAnimating) return;
id oldDelegate = tabAnimated.oldDelegate;
SEL sel = @selector(scrollViewDidZoom:);
((void (*)(id, SEL, UIScrollView *))objc_msgSend)((id)oldDelegate, sel, scrollView);
Expand All @@ -392,7 +390,6 @@ - (void)tab_scrollViewDidZoom:(UIScrollView *)scrollView {
// called on start of dragging (may require some time and or distance to move)
- (void)tab_scrollViewWillBeginDragging:(UIScrollView *)scrollView {
TABFormAnimated *tabAnimated = (TABFormAnimated *)(scrollView.tabAnimated);
if (tabAnimated.isAnimating) return;
id oldDelegate = tabAnimated.oldDelegate;
SEL sel = @selector(scrollViewWillBeginDragging:);
((void (*)(id, SEL, UIScrollView *))objc_msgSend)((id)oldDelegate, sel, scrollView);
Expand All @@ -401,7 +398,6 @@ - (void)tab_scrollViewWillBeginDragging:(UIScrollView *)scrollView {
// called on finger up if the user dragged. velocity is in points/millisecond. targetContentOffset may be changed to adjust where the scroll view comes to rest
- (void)tab_scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset API_AVAILABLE(ios(5.0)) {
TABFormAnimated *tabAnimated = (TABFormAnimated *)(scrollView.tabAnimated);
if (tabAnimated.isAnimating) return;
id oldDelegate = tabAnimated.oldDelegate;
SEL sel = @selector(scrollViewWillEndDragging:withVelocity:targetContentOffset:);
((void (*)(id, SEL, UIScrollView *, CGPoint, CGPoint *))objc_msgSend)((id)oldDelegate, sel, scrollView, velocity, targetContentOffset);
Expand All @@ -410,71 +406,62 @@ - (void)tab_scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(C
// called on finger up if the user dragged. decelerate is true if it will continue moving afterwards
- (void)tab_scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
TABFormAnimated *tabAnimated = (TABFormAnimated *)(scrollView.tabAnimated);
if (tabAnimated.isAnimating) return;
id oldDelegate = tabAnimated.oldDelegate;
SEL sel = @selector(scrollViewDidEndDragging:willDecelerate:);
((void (*)(id, SEL, UIScrollView *, BOOL))objc_msgSend)((id)oldDelegate, sel, scrollView, decelerate);
}

- (void)tab_scrollViewWillBeginDecelerating:(UIScrollView *)scrollView {
TABFormAnimated *tabAnimated = (TABFormAnimated *)(scrollView.tabAnimated);
if (tabAnimated.isAnimating) return;
id oldDelegate = tabAnimated.oldDelegate;
SEL sel = @selector(scrollViewWillBeginDecelerating:);
((void (*)(id, SEL, UIScrollView *))objc_msgSend)((id)oldDelegate, sel, scrollView);
}

- (void)tab_scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
TABFormAnimated *tabAnimated = (TABFormAnimated *)(scrollView.tabAnimated);
if (tabAnimated.isAnimating) return;
id oldDelegate = tabAnimated.oldDelegate;
SEL sel = @selector(scrollViewDidEndDecelerating:);
((void (*)(id, SEL, UIScrollView *))objc_msgSend)((id)oldDelegate, sel, scrollView);
}

- (void)tab_scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView {
TABFormAnimated *tabAnimated = (TABFormAnimated *)(scrollView.tabAnimated);
if (tabAnimated.isAnimating) return;
id oldDelegate = tabAnimated.oldDelegate;
SEL sel = @selector(scrollViewDidEndScrollingAnimation:);
((void (*)(id, SEL, UIScrollView *))objc_msgSend)((id)oldDelegate, sel, scrollView);
}

- (nullable UIView *)tab_viewForZoomingInScrollView:(UIScrollView *)scrollView {
TABFormAnimated *tabAnimated = (TABFormAnimated *)(scrollView.tabAnimated);
if (tabAnimated.isAnimating) return nil;
id oldDelegate = tabAnimated.oldDelegate;
SEL sel = @selector(viewForZoomingInScrollView:);
return ((UIView * (*)(id, SEL, UIScrollView *))objc_msgSend)((id)oldDelegate, sel, scrollView);
}

- (void)tab_scrollViewWillBeginZooming:(UIScrollView *)scrollView withView:(nullable UIView *)view API_AVAILABLE(ios(3.2)) {
TABFormAnimated *tabAnimated = (TABFormAnimated *)(scrollView.tabAnimated);
if (tabAnimated.isAnimating) return;
id oldDelegate = tabAnimated.oldDelegate;
SEL sel = @selector(scrollViewWillBeginZooming:withView:);
((void (*)(id, SEL, UIScrollView *, UIView *))objc_msgSend)((id)oldDelegate, sel, scrollView, view);
}

- (void)tab_scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(nullable UIView *)view atScale:(CGFloat)scale {
TABFormAnimated *tabAnimated = (TABFormAnimated *)(scrollView.tabAnimated);
if (tabAnimated.isAnimating) return;
id oldDelegate = tabAnimated.oldDelegate;
SEL sel = @selector(scrollViewDidEndZooming:withView:atScale:);
((void (*)(id, SEL, UIScrollView *, UIView *, CGFloat))objc_msgSend)((id)oldDelegate, sel, scrollView, view, scale);
}

- (BOOL)tab_scrollViewShouldScrollToTop:(UIScrollView *)scrollView {
TABFormAnimated *tabAnimated = (TABFormAnimated *)(scrollView.tabAnimated);
if (tabAnimated.isAnimating) return NO;
id oldDelegate = tabAnimated.oldDelegate;
SEL sel = @selector(scrollViewShouldScrollToTop:);
return ((BOOL (*)(id, SEL, UIScrollView *))objc_msgSend)((id)oldDelegate, sel, scrollView);
}

- (void)tab_scrollViewDidScrollToTop:(UIScrollView *)scrollView {
TABFormAnimated *tabAnimated = (TABFormAnimated *)(scrollView.tabAnimated);
if (tabAnimated.isAnimating) return;
id oldDelegate = tabAnimated.oldDelegate;
SEL sel = @selector(scrollViewShouldScrollToTop:);
((void (*)(id, SEL, UIScrollView *))objc_msgSend)((id)oldDelegate, sel, scrollView);
Expand All @@ -484,7 +471,6 @@ - (void)tab_scrollViewDidScrollToTop:(UIScrollView *)scrollView {
*/
- (void)tab_scrollViewDidChangeAdjustedContentInset:(UIScrollView *)scrollView API_AVAILABLE(ios(11.0), tvos(11.0)) {
TABFormAnimated *tabAnimated = (TABFormAnimated *)(scrollView.tabAnimated);
if (tabAnimated.isAnimating) return;
id oldDelegate = tabAnimated.oldDelegate;
SEL sel = @selector(scrollViewDidChangeAdjustedContentInset:);
((void (*)(id, SEL, UIScrollView *))objc_msgSend)((id)oldDelegate, sel, scrollView);
Expand Down
12 changes: 6 additions & 6 deletions TABAnimatedDemo/TABAnimatedDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2030,9 +2030,9 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = "";
CODE_SIGN_IDENTITY = "iPhone Developer";
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 2.6.2;
CURRENT_PROJECT_VERSION = 2.6.3;
DEBUG_INFORMATION_FORMAT = dwarf;
DEVELOPMENT_TEAM = JGZKPAYJ7R;
ENABLE_BITCODE = NO;
Expand All @@ -2049,7 +2049,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 2.6.2;
MARKETING_VERSION = 2.6.3;
OTHER_LDFLAGS = (
"-Xlinker",
"-interposable",
Expand All @@ -2066,9 +2066,9 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = "";
CODE_SIGN_IDENTITY = "iPhone Developer";
CODE_SIGN_IDENTITY = "Apple Development: Wenhu An (629MZJMJ23)";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 2.6.2;
CURRENT_PROJECT_VERSION = 2.6.3;
DEVELOPMENT_TEAM = JGZKPAYJ7R;
ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = (
Expand All @@ -2084,7 +2084,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 2.6.2;
MARKETING_VERSION = 2.6.3;
OTHER_LDFLAGS = (
"-Xlinker",
"-interposable",
Expand Down

0 comments on commit 0c54a44

Please sign in to comment.