iOS 状态栏点击事件

来源:互联网 发布:c语言怎么取反 编辑:程序博客网 时间:2024/05/17 23:46

iOS应用中,点击状态栏会使得滚动视图回滚到顶部,但如果当前视图控制器中包含多个滚动视图就会失效。

这里我们可以通过以下的方法获取状态栏的点击事件。

方法一:AppDelegate.m

#pragma mark - Status Bar Touch Eventstatic NSString * const kStatusBarTappedNotification = @"statusBarTappedNotification";- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{    [super touchesBegan:touches withEvent:event];    CGPoint touchLocation = [[[event allTouches] anyObject] locationInView:self.window];    CGRect statusBarFrame = [UIApplication sharedApplication].statusBarFrame;    if (CGRectContainsPoint(statusBarFrame, touchLocation))    {        [self statusBarTouchedAction];    }}- (void)statusBarTouchedAction {    [[NSNotificationCenter defaultCenter] postNotificationName:kStatusBarTappedNotification object:nil];}
0 0
原创粉丝点击