I am just trying to write code that only when the device is upside down will a label "dave" not be hidden. Right now the label "dave" is shown in all 4 orientations. This is my code.
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
}}}
Aucun commentaire:
Enregistrer un commentaire