static UIWindow *topWindow_;
static UIScrollView *scrollView_;
/**
* 显示顶部窗口
*/
+ (void)show
{
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.25 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
topWindow_ = [[UIWindow alloc] init];
topWindow_.windowLevel = UIWindowLevelAlert;
topWindow_.frame = CGRectMake(60, 0, fView_Width(kWindow), 20);
topWindow_.backgroundColor = [UIColor clearColor];
topWindow_.hidden = NO;
[topWindow_ addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(topWindowClick)]];
});
}
/**
* 监听顶部窗口点击
*/
+ (void)topWindowClick
{
UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow;
[self searchAllScrollViewsInView:keyWindow];
}
/**
* 找到参数view中所有的UIScrollView
*/
+ (void)searchAllScrollViewsInView:(UIView *)view
{
// 递归遍历所有的子控件
for (UIView *subview in view.subviews) {
[self searchAllScrollViewsInView:subview];
}
// 判断子控件类型(如果不是UIScrollView,直接返回)
if (![view isKindOfClass:[UIScrollView class]]) return;
// 找到了UIScrollView
UIScrollView *scrollView = (UIScrollView *)view;
// 让UIScrollView滚动到最前面
// 让CGRectMake(0, 0, 1, 1)这个矩形框完全显示在scrollView的frame框中
// [scrollView scrollRectToVisible:CGRectMake(0, 0, 1, 1) animated:YES];
if (scrollView == scrollView_) {
[scrollView setContentOffset:CGPointMake(scrollView.contentOffset.x, -scrollView.contentInset.top) animated:YES];
}
}
+ (void)configScrollView:(UIScrollView *)scrollView {
scrollView_ = scrollView;
}