2016-03-08 64 views
0

當我將設備置於風景模式時,背景設置錯誤。我如何解決它?我也可以用它來了解如何將整個應用程序置於橫向模式。背景漸變在模式風景中看不到正確

override func viewDidLoad() { 
    super.viewDidLoad() 
    //BACKGROUND FONDO 
    //A linear Gradient Consists of two colours: top colour and bottom colour 
    let topColor = UIColor(red: 15.0/255.0, green: 118.0/255.0, blue: 128.0/255.0, alpha: 1.0) 
    let bottomColor = UIColor(red: 84.0/255.0, green: 187.0/255.0, blue: 187.0/255.0, alpha: 1.0)  

    //Add the top and bottom colours to an array and setup the location of those two. 
    let gradientColors: [CGColor] = [topColor.CGColor, bottomColor.CGColor] 
    let gradientLocations: [CGFloat] = [0.0, 1.0] 

    //Create a Gradient CA layer 
    let gradientLayer: CAGradientLayer = CAGradientLayer() 
    gradientLayer.colors = gradientColors 
    gradientLayer.locations = gradientLocations 

    gradientLayer.frame = self.view.bounds 
    self.view.layer.insertSublayer(gradientLayer, atIndex: 0) 
} //FIN BACKGROUND GRADIENT 

回答

1

在你的情況下,漸變是一個圖層,而不是視圖。這意味着當包含層發生變化時(例如在旋轉過程中),它不會調整大小或更改位置。在旋轉過程中,您必須手動更改子圖層的框架。

+0

我如何改變框架? –

+0

你必須在循環後重復這一行:'gradientLayer.frame = self.view.bounds' – Tobol

+0

謝謝,旋轉的功能是什麼? –