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