【发布时间】:2017-01-15 09:27:53
【问题描述】:
我知道之前有人问过这个问题并尝试实施建议的解决方案,但它对我不起作用。也许我做错了。你有什么想法吗?
这是我的代码:
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var test: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
test.backgroundColor = UIColor.darkGray
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated) // No need for semicolon
func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
if UIDevice.current.orientation.isLandscape {
test.backgroundColor = UIColor.purple
} else {
test.backgroundColor = UIColor.blue
}
}
}
}
【问题讨论】:
-
我尝试遵循这些建议,但在我的情况下无法实施。
标签: ios swift uiviewcontroller uidevice