WWObserve
Observe whether the subviews are displayed on the screen when the scroll view stops scrolling.
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