0
我只是想寫代碼,只有當設備顛倒時,標籤「dave」纔不會被隱藏。現在,標籤「dave」以全部4個方向顯示。這是我的代碼。當方向改變時,效果不被應用(swift3)
import UIKit
class ViewController: UIViewController {
@IBOutlet var dave: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
s()
}
func s() {
if UIDevice.current.orientation == UIDeviceOrientation.landscapeLeft {
dave.isHidden = true
} else if UIDevice.current.orientation == UIDeviceOrientation.landscapeRight {
dave.isHidden = true
} else if UIDevice.current.orientation == UIDeviceOrientation.portrait {
dave.isHidden = true
} else if UIDevice.current.orientation == UIDeviceOrientation.portraitUpsideDown {
dave.isHidden = false
}}}
你知道* viewDidLoad *被解僱**一次**,對嗎?不要在那裏調用你的「s」功能 - 當方向改變時調用它。 (是的,你也想檢查* viewWillAppear *中的初始方向。) – dfd