2017-09-18 25 views
1

我正試圖將我的應用程序轉換爲兼容iPhone X的應用程序。我的視圖控制器中有一個頂部佈局爲20像素的桌子。現在下面是兩個設備iPhone X Topbar問題

iPhone截圖8 iPhone 8

iPhone X iPhone-X

現在我正在用iPhone X的彩色背景中的白頂吧。

如果我將表頂部佈局設置爲0,那麼單元格會與我不需要的頂欄重疊。

任何人都可以提出什麼問題?任何建議都會很棒。

回答

2

主視圖控制器的視圖的背景更改爲您想要的顏色:

enter image description here enter image description here

2

您不應該遵循頂層佈局,而應該遵循新的安全區域。那麼一切都應該沒問題。

+0

請問你能解釋一點點嗎? –

+0

您可以在這裏閱讀:「所有的應用程序都應該遵循由UIKit定義的安全區域和佈局邊距,以確保根據設備和上下文進行適當的插入。」 https://developer.apple.com/ios/human-interface-guidelines/overview/iphone-x/ – Alper

1

添加在Appdelegate.m

if ([UIScreen mainScreen].bounds.size.height >= 812) 
    { 
     [application setStatusBarStyle:UIStatusBarStyleLightContent]; 
     self.window.clipsToBounds =YES; 
     self.window.frame = CGRectMake(0,40,self.window.frame.size.width,self.window.frame.size.height-20); 
    } 
2

可以爲頂欄的背景顏色(狀態欄)在應用程序啓動期間或視圖控制器的viewDidLoad期間..

extension UIApplication { 

    var statusBarView: UIView? { 
     return value(forKey: "statusBar") as? UIView 
    } 

} 

// Set upon application launch 
class AppDelegate: UIResponder, UIApplicationDelegate { 

    var window: UIWindow? 

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 
     UIApplication.shared.statusBarView?.backgroundColor = UIColor.green 
     return true 
    } 
} 


or 
// Set it from your view controller 
class ViewController: UIViewController { 

    override func viewDidLoad() { 
     super.viewDidLoad() 
     UIApplication.shared.statusBarView?.backgroundColor = UIColor.green 
    } 

} 



下面是結果:

enter image description here

1

,你可以看到這個空白基本上是頭,我不知道爲什麼它在iPhone X. 發生只是試圖重寫方法

- (CGFloat的)的tableView:(UITableView的*)的tableView heightForHeaderInSection:(NSInteger的)部分

然後返回0.01F;

嘗試和完美工作