Skip to content

Instantly share code, notes, and snippets.



Created Jun 14, 2013
What would you like to do?
@interface UIScrollView (willBeginScrollingAnimation)
@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

This comment has been minimized.

Copy link

@longlongjump longlongjump commented Jun 14, 2013

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