iOS开发 获取状态栏的点击事件
Posted 邸伟男
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了iOS开发 获取状态栏的点击事件相关的知识,希望对你有一定的参考价值。
首先我们追踪UIStatusBar的触摸事件,需要在AppDelegate里面加入以下代码
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [super touchesBegan:touches withEvent:event]; CGPoint location = [[[event allTouches] anyObject] locationInView:self.window]; CGRect statusBarFrame = [UIApplication sharedApplication].statusBarFrame; if (CGRectContainsPoint(statusBarFrame, location)) { [self statusBarTouchedAction]; } }
然后在statusBarTouchedAction方法中将显示在当前keyWindow里面的scrollView滚动到顶部
- (void)statusBarTouchedAction {
[[DDTopWindow defaultDDTopWindow] scrollsToTop];
}
下面来看DDTopWindow
@interface DDTopWindow : UIView
+ (instancetype)defaultDDTopWindow;
- (void)configScrollView:(UIScrollView *)scrollView isCanTop:(BOOL)isCanTop;
- (void)scrollsToTop;
@end
#import "DDTopWindow.h"
static UIScrollView *scrollView_;
@interface DDTopWindow ()
@property (nonatomic, assign) BOOL isCan;
@end
@implementation DDTopWindow
SYNTHESIZE_SINGLETON_FOR_CLASS_ARC(DDTopWindow);
- (void)configScrollView:(UIScrollView *)scrollView isCanTop:(BOOL)isCanTop {
scrollView_ = scrollView;
self.isCan = isCanTop;
}
- (void)scrollsToTop {
if (scrollView_.scrollEnabled) {
[scrollView_ setContentOffset:CGPointMake(scrollView_.contentOffset.x, -scrollView_.contentInset.top) animated:YES];
}
}
@end
以上是关于iOS开发 获取状态栏的点击事件的主要内容,如果未能解决你的问题,请参考以下文章