gpt4 book ai didi

ios - Swift - 如何检测方向变化

转载 作者:IT王子 更新时间:2023-10-29 04:58:03 25 4
gpt4 key购买 nike

我想将两张图片添加到单张图片 View 中(即横向一张图片和纵向另一张图片)但我不知道如何使用快速语言检测方向变化。

我试过这个答案,但它只需要一张图片

override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
if UIDevice.currentDevice().orientation.isLandscape.boolValue {
print("Landscape")
} else {
print("Portrait")
}
}

我是 iOS 开发的新手,非常感谢任何建议!

最佳答案

let const = "Background" //image name
let const2 = "GreyBackground" // image name
@IBOutlet weak var imageView: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()

imageView.image = UIImage(named: const)
// Do any additional setup after loading the view.
}

override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransition(to: size, with: coordinator)
if UIDevice.current.orientation.isLandscape {
print("Landscape")
imageView.image = UIImage(named: const2)
} else {
print("Portrait")
imageView.image = UIImage(named: const)
}
}

关于ios - Swift - 如何检测方向变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38894031/

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