2016-03-29 19 views
0

ich dies versuchte mit der Statusleiste Farbe zu ändern, arbeitet im Portrait fein,ios - Statusleiste Farbe - iphone Landschaft Ausgabe

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

und ich will es nicht in der Landschaft auf dem iPhone. teilweise

so habe ich versucht, diese

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) 

} 

aber das Ergebnis ist umständlich, zeigt die Statusleiste. enter image description here Beigefügt.

Jede Hilfe wird geschätzt.

+1

Sie können nicht nur wieder eine neue Proxy-Ansicht mit Ein klarer Hintergrund, Sie müssen den bereits vorhandenen entfernen. Sie sollten einen Verweis darauf beibehalten, bevor Sie ihn als Unteransicht hinzufügen und entfernen, wenn sich das Gerät im Querformat befindet. – dan

Antwort

1

Ich sehe, dass Sie viewProxy zweimal hinzugefügt haben. Beim ersten Mal funktionieren die Bußgelder. Aber wenn man eine andere Ansicht rotiert und die letzte Ansicht immer noch hier.

So können Sie eine globale für Ansicht erstellen:

var proxyViewForStatusBar : UIView! 

In ViewDidload:

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

wenn drehen:

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() 
    } 

} 
Verwandte Themen