在我的應用程式中,所有螢屏都具有縱向方向。如何只允許單個 UIViewController 處于兩種方向模式:縱向和倒置?當用戶旋轉 iPhone 時, UIViewController 也應該旋轉。
uj5u.com熱心網友回復:
首先,在您的應用程式中,除了一個螢屏之外的所有螢屏都是縱向的。因此,您不能將應用程式的方向設定為縱向。所以將設備方向設定為縱向和橫向。
在 ViewDidLoad 中將以下代碼放在您需要橫向的螢屏上
let value = UIInterfaceOrientation.landscapeLeft.rawValue
UIDevice.current.setValue(value, forKey: "orientation")
和
override var shouldAutorotate: Bool {
return true
}
在 viewDidLoad 中只需要縱向方向的所有螢屏上放置以下代碼
let value = UIInterfaceOrientation.portrait.rawValue
UIDevice.current.setValue(value, forKey: "orientation")
uj5u.com熱心網友回復:
如果您有任何連續呼叫的函式,那么您可以檢查此函式內的設備方向為-
if UIDevice.current.orientation == UIDeviceOrientation.portraitUpsideDown {
// set your view constraints
}
if UIDevice.current.orientation == UIDeviceOrientation.portrait {
// set your view constraints
}
否則,您應該創建一個監視功能并檢查該功能內的設備方向。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/329707.html
