簡體   English   中英

iOS-狀態欄顏色-iPhone橫向問題

[英]ios - status bar color - iphone landscape issue

我嘗試使用它來更改狀態欄的顏色,在人像中效果很好,

let proxyViewForStatusBar : UIView = UIView(frame: CGRectMake(0, 0,self.view.frame.size.width, 20))     
proxyViewForStatusBar.backgroundColor=UIColor.purpleColor()
self.view.addSubview(proxyViewForStatusBar)

而且我不想在iPhone上使用它。

所以我嘗試了這個

override func didRotateFromInterfaceOrientation(fromInterfaceOrientation: UIInterfaceOrientation) {


    let proxyViewForStatusBar : UIView = UIView(frame: CGRectMake(0, 0,self.view.frame.size.width, 20))



    if UIDevice.currentDevice().orientation.isLandscape.boolValue && UIDevice.currentDevice().userInterfaceIdiom == .Phone{

        proxyViewForStatusBar.backgroundColor = UIColor.clearColor()
    }else {
        proxyViewForStatusBar.backgroundColor=UIColor.purpleColor()
    }

    self.view.addSubview(proxyViewForStatusBar)

}

但結果很尷尬,狀態欄會部分顯示。 在此處輸入圖片說明 附上。

任何幫助表示贊賞。

我看到您已經兩次添加了viewProxy。 第一次工作罰款。 但是當您旋轉另一個視圖時,最后一個視圖仍在此處。

因此,您可以創建一個全局視圖:

 var proxyViewForStatusBar : UIView!

ViewDidload

proxyViewForStatusBar= UIView(frame: CGRectMake(0, 0,self.view.frame.size.width, 20))     
proxyViewForStatusBar.backgroundColor=UIColor.purpleColor()
self.view.addSubview(proxyViewForStatusBar)

旋轉時:

override func didRotateFromInterfaceOrientation(fromInterfaceOrientation: UIInterfaceOrientation) {
    proxyViewForStatusBar.frame = CGRectMake(0, 0,self.view.frame.size.width, 20)
    if UIDevice.currentDevice().orientation.isLandscape.boolValue && UIDevice.currentDevice().userInterfaceIdiom == .Phone{

        proxyViewForStatusBar.backgroundColor = UIColor.clearColor()
    }else {
        proxyViewForStatusBar.backgroundColor=UIColor.purpleColor()
    }

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM