WWViewScrollObserve 0.0.1

WWViewScrollObserve 0.0.1

Maintained by Wayne2Wen.



  • By
  • Wayne2Wen

WWViewScrollObserve

License MIT  CocoaPods  Support 

You can get view's visible rect and observe whether it is displaying on the screen when the scroll view stops scrolling. Listen for all the scroll methods in UIKit that have animation in them.

  • Scroll begin trigger methods
// delegate method
- (void)scrollViewDidScroll:(UIScrollView *)scrollView;

// instance method: only animated == YES
- (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated;

- (void)scrollRectToVisible:(CGRect)rect animated:(BOOL)animated; 
  • Scroll end trigger methods
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate;

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView;

- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView;

- (void)scrollViewDidScrollToTop:(UIScrollView *)scrollView;

setContentOffset: and other methods without scrolling animation(setContentOffset:animated: and scrollRectToVisible:animated:, parameter animated is NO) are not listened for, you can use [scrollView ww_postScrollBegin] notify view is scrolling, and use [scrollView ww_postScrollEnd] notify view did end scroll

Use

Add observe

[scrollView ww_registerObserve];

serve operation

view.ww_visibleHandler = ^(CGRect viewRect, CGRect containerRect, BOOL stop) {
    NSString *stopStr = stop ? @"🎈End" : @"🌲Begin";
    NSString *str = [NSString stringWithFormat:@"%zd-%@", self.index, stopStr];
    NSLog(@"%@Scroll\nViewRect:%@, \nContainerRect:%@", str, NSStringFromCGRect(viewRect), NSStringFromCGRect(containerRect));
};

Remove observe

[scrollView ww_unregisterObserveWithHandler:^(BOOL isRegistedBefore) {
    // need to do something when unregister  
}];

安装

pod 'WWViewScrollObserve'
  • 下载ZIP包,将WWViewScrollObserve资源文件拖到工程中。

其他

本库依赖三方库ReactiveObjC。在使用前,您可以查看示例程序WWViewScrollObserveDemo