【问题标题】:ios - status bar color - iphone landscape issueios - 状态栏颜色 - iphone横向问题
【发布时间】:2016-03-29 15:37:44
【问题描述】:

我尝试使用它来更改状态栏颜色,纵向效果很好,

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)

}

但结果很尴尬,状态栏显示部分。Attached。

感谢任何帮助。

【问题讨论】:

  • 您不能只添加另一个具有清晰背景的新代理视图,您需要删除已经存在的代理视图。您应该在将其添加为子视图之前保留对它的引用,并在设备处于横向时将其删除。

标签: ios iphone


【解决方案1】:

我看到你已经添加了两次 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()
    }

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-06
    • 1970-01-01
    • 2012-06-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多