簡體   English   中英

如何停止設備方向更改

[英]How to stop the device Orientation changing

我正在開發一個在啟動時處於縱向模式的應用程序。 在那之后,我將出於某種目的的SDK添加到我的項目中。 在集成SDK的過程中,需要在“常規”窗格中同時選中“縱向”和“橫向”。 因此,我按照SDK集成手冊中的說明進行了設置。

在此處輸入圖片說明

之后,當我在設備中運行項目並將其向右旋轉時,應用程序設備的方向就會改變。 在不干擾SDK的情況下如何設置方向是固定的。

如果在應用啟動后無法立即設置方向,則可能需要停止每個視圖控制器或其基本導航控制器之一的方向

斯威夫特3:

class YourBaseNavigationController: UINavigationController {
override func viewDidLoad() {
    super.viewDidLoad()
    UIDevice.current.setValue(UIInterfaceOrientation.portrait.rawValue, forKey: "orientation")
}
override var shouldAutorotate: Bool {
    return false
}
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
    return .portrait
}
override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation {
    return .portrait
}}

使用YourBaseNavigationController作為導航控制器。基本上,此導航控制器中的所有視圖控制器都將僅支持縱向模式。

取消標記支票左橫向和右橫向

您需要通過代碼禁用定向。

在您的RootViewController中添加以下代碼:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);//set 'return NO'; for stop orientation
}

斯威夫特

override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
    return UIInterfaceOrientationMask.Portrait
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM