iOS 状态栏点击事件

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

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

方法一:AppDelegate.m

#pragma mark - Status Bar Touch Event

static 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];
}

你可能感兴趣的:(iOS-框架)