我尝试使用它来更改状态栏颜色,在肖像中工作正常,
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)
}
感谢任何帮助。
答案 0 :(得分: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()
}
}