Skip to content

Instantly share code, notes, and snippets.

@gavrix
Created June 14, 2013 20:37
Show Gist options
  • Save gavrix/5785069 to your computer and use it in GitHub Desktop.
Save gavrix/5785069 to your computer and use it in GitHub Desktop.
@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
@longlongjump
Copy link

i guess you can just observe 'contentOffset' of scrollview

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment