WWObserve
监视当滚动视图停止滚动时子视图是否显示在屏幕上。
Observe 的方法有
- scrollView 代理方法
- (void)scrollViewDidScroll:(UIScrollView *)scrollView;
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate;
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView;
- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView;
- (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView;
- (void)scrollViewDidScrollToTop:(UIScrollView *)scrollView;
- scrollView 实例方法
- (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated;
- (void)scrollRectToVisible:(CGRect)rect animated:(BOOL)animated;
使用
需要被监测的 scrollView
[scrollView ww_registerObserve];
在这个 scrollView
的需要被监测滚动的 subview
的 ww_visibleHandler
中写入监测代码
@weakify(self);
view.ww_visibleHandler = ^(CGRect viewRect, CGRect containerRect, BOOL stop) {
@strongify(self);
NSString *stopStr = stop ? @"🎈End" : @"🌲Begin";
NSString *str = [NSString stringWithFormat:@"%zd-%@", self.index, stopStr];
NSLog(@"%@Scroll\nViewRect:%@, \nContainerRect:%@", str, NSStringFromCGRect(viewRect), NSStringFromCGRect(containerRect));
};
安装
-
CocoaPods 安装:
pod 'WWObserve'
-
下载 ZIP 包,将
WWObserve
资源文件拖放到工程中。
其他
本库依赖三方库 ReactiveObjC
。在使用前,您可以查看示例程序 WWObserveDemo