近在做模仿新浪微博的圖片瀏覽系統(tǒng),快要完成的時(shí)候發(fā)現(xiàn)狀態(tài)欄并沒有完全的隱藏掉.
在充電狀態(tài)下還是能看到狀態(tài)欄
原來的代碼是
- (void)show { UIWindow *window = [UIApplication sharedApplication].keyWindow; self.frame = window.bounds; [window addSubview:self];}
查找資料,才知道
通過[UIApplication sharedApplication].keyWindow
獲取得到的UIWindow不一定是在界面的最上面.UIWindow有一個(gè)UIWindowLevel的屬性,該屬性定義了UIWindow的層級(jí),系統(tǒng)定義的WindowLevel一共有3種取值:
UIWindowLevelNormal
UIWindowLevelAlert
UIWindowLevelStatusBar
將下面這些代碼輸出:
NSLog(@"UIWindowLevelNormal==%f, UIWindowLevelAlert==%f, UIWindowLevelStatusBar==%f",UIWindowLevelNormal,UIWindowLevelAlert,UIWindowLevelStatusBar);
得到的結(jié)果是:
打印結(jié)果
所以,重點(diǎn)就是你只要通過修改Window的UIWindowLevel屬性,就能夠使得添加到UIWindow上的UIView覆蓋到狀態(tài)欄只上了.
這是修改之后的代碼:
- (void)show { UIWindow *window = [UIApplication sharedApplication].keyWindow; window.windowLevel = UIWindowLevelAlert; self.frame = window.bounds; [window addSubview:self];}
效果:
改變UIWindowLevel之后的效果