一.新建一个类(继承NSObject)
.h文件声明方法
<pre>
- (void)show;
- (void)hide;
</pre>
.m文件实现方法
<pre>
static UIWindow *window_;
-
(void)initialize
{
window_ = [[UIWindow alloc] init];
window_.frame = CGRectMake(0, 0, UIWidth, 20);
window_.windowLevel = UIWindowLevelAlert;
[window_ addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(windowClick)]];
} -
(void)show
{
window_.hidden = NO;
} -
(void)hide
{
window_.hidden = YES;
}
/**
- 监听窗口点击
*/
- (void)windowClick
{
UIWindow *window = [UIApplication sharedApplication].keyWindow;
[self searchScrollViewInView:window];
}
-
(void)searchScrollViewInView:(UIView *)superview
{
for (UIScrollView *subview in superview.subviews) {
// 如果是scrollview, 滚动最顶部
if ([subview isKindOfClass:[UIScrollView class]] && subview.isShowingOnKeyWindow) {
CGPoint offset = subview.contentOffset;
offset.y = - subview.contentInset.top;
[subview setContentOffset:offset animated:YES];
}// 继续查找子控件 [self searchScrollViewInView:subview];
}
}
</pre>
网友评论