คุณอาจเจอสถานการณ์ที่คุณต้องแสดง UI ในการวางแนวที่เฉพาะเจาะจงอาจเป็นแนวนอนหรือแนวตั้ง
เราจะได้เห็นวิธีการล็อกการวางแนวโดยทางโปรแกรมโดยใช้ Swift ใน iOS
เปิด Xcode → โครงการใหม่ → ViewController.swift เขียนโค้ดด้านล่าง
// Set the shouldAutorotate to False
override open var shouldAutorotate: Bool {
return false
}
// Specify the orientation.
override open var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return .portrait
}
