@interface UIScrollView (willBeginScrollingAnimation) | |
@end | |
@implementation UIScrollView (willBeginScrollingAnimation) | |
#pragma clang diagnostic push | |
#pragma clang diagnostic ignored "-Wobjc-method-access" | |
+(void)load { | |
Method setContentOffsetAnimatedMethod = class_getInstanceMethod([UIScrollView class], @selector(setContentOffset:animated:)); | |
IMP oldImplementation = method_getImplementation(setContentOffsetAnimatedMethod); | |
method_setImplementation(setContentOffsetAnimatedMethod, imp_implementationWithBlock(^(UIScrollView *_self, CGPoint offset, BOOL animated) { | |
if ([_self.delegate respondsToSelector:@selector(scrollViewWillBeginScrollingAnimation:)] && animated && | |
CGPointEqualToPoint(_self.contentOffset, offset) == NO) { | |
[_self.delegate scrollViewWillBeginScrollingAnimation:_self]; | |
} | |
oldImplementation(_self, @selector(setContentOffset:animated:), offset, animated); | |
})); | |
} | |
#pragma clang diagnostic pop | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
i guess you can just observe 'contentOffset' of scrollview