当我将设备置于横向模式时,背景设置错误。我如何解决它?我还可以用来了解如何将整个应用程序置于横向模式。
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
最佳答案
在您的情况下,渐变是图层,而不是视图。这意味着在包含图层更改时(例如在旋转过程中),它不会调整大小或更改位置。您必须在旋转期间手动更改子图层的框架。
关于ios - 背景渐变在模式横向下无法正确显示,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35869036/