Created
June 14, 2013 20:37
-
-
Save gavrix/5785069 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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
i guess you can just observe 'contentOffset' of scrollview