IOS 6 升到 IOS7 之后出現的狀況
新建一個工程,刪除默認的ViewController,拖拽一個TableViewController到storyboard。
即使沒有勾選 "Extend Edges Under {Top, Bottom, Opaque} Bars"
或者
self.edgesForExtendedLayout=UIRectEdgeNone; self.extendedLayoutIncludesOpaqueBars=NO; self.automaticallyAdjustsScrollViewInsets=NO;
UITableView都會在status bar下面。
通常會向下移動20px,不過這樣並不是蘋果建議的。
兩種方式
- 嵌入TableViewController到Navigation Controller(Editor > Embed In > Navigation Controller) 不選擇 “Shows Navigation Bar”
- 用AutoLayout 並嵌入TableView到另一個View。 創建一個空ViewController拖拽一個TableView。然后Ctrl-drag TableView 到 "Top Layout Guide" 出現選擇“Vertical Spaceing”。這樣就會在statusbar下面了。
-
- (void) viewDidLayoutSubviews { CGRect viewBounds = self.view.bounds; CGFloat topBarOffset = self.topLayoutGuide.length; viewBounds.origin.y = topBarOffset * -1; self.view.bounds = viewBounds; }
第三種方式沒有試過。
參考