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

發佈了68 篇原創文章 · 獲贊 0 · 訪問量 6萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章