Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> iOS

วิธีล็อก Screen Orientation ด้วยโปรแกรมใน iOS

บางกรณีต้องการให้ UI แสดงใน Orientation เฉพาะ เช่น Portrait หรือ Landscape เท่านั้น

วิธีล็อก Orientation ด้วยโปรแกรมใน Swift:

ใน ViewController.swift ใส่โค้ด:

// ปิด Auto Rotate
override open var shouldAutorotate: Bool {
return false
}
// ระบุ Orientation ที่รองรับ
override open var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return .portrait
}

วิธีล็อก Screen Orientation ด้วยโปรแกรมใน iOS