gpt4 book ai didi

ios - 背景渐变在横向模式下看不正确

转载 作者:行者123 更新时间:2023-11-29 01:10:02 25 4
gpt4 key购买 nike

当我将设备置于横向模式时,背景设置错误。我如何解决它?我还可以用来了解如何将整个应用程序置于横向模式。

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

最佳答案

在您的情况下,渐变是图层,而不是 View 。这意味着它不会在包含图层更改时(例如在旋转期间)调整大小或更改位置。您必须在旋转期间手动更改子层的框架。

关于ios - 背景渐变在横向模式下看不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35869036/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com