![](/img/trans.png)
[英]Extend UIViewController's view without a navigation bar under status bar
[英]When creating a view in IOS 7's loadView method of UIViewController, why does UIScreen's mainApplication frame begin beneath status bar?
我正在嘗試以編程方式創建視圖。 我了解從IOS7開始,狀態欄與視圖重疊。 當我像這樣在loadView中創建視圖時,幀從x / y 0,20開始,而不是我期望的0,0,並且漸變背景沒有延伸到狀態欄下方的屏幕頂部。
- (void)loadView {
UIView *view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
CALayer *layer = [MyCustomGradients darkBlueToLightBlueGradient];
layer.frame = view.frame;
[view.layer insertSublayer:layer atIndex:0];
self.view = view;
}
如果我沒有覆蓋loadView
,而是在自動創建的view屬性的viewDidLoad
設置了漸變背景圖層,則框架的原點正確為0,0,並且根據需要顯示背景。
任何提示將不勝感激!
那是因為
[[UIScreen mainScreen] applicationFrame]
返回沒有狀態欄的屏幕邊界。 只需使用
[[UIScreen mainScreen] bounds]
相反,視圖將正確定位。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.