提出我有一個ViewController,可以在應用程序的任何地方呈現。我用這個代碼UIApplication.sharedApplication().keyWindow?.rootViewController?.presentedViewController?.presentViewController
來呈現它。所以我想禁用方向,只有肖像被支持。我已經嘗試了很多解決方案,實施shouldAutorotate/supportedInterfaceOrientations/preferredInterfaceOrientationForPresentation
,但沒有任何幫助。任何人都面臨這個問題如何禁用ViewController的方向與UIApplication.keyWindow()
0
A
回答
0
你在viewDidLoad中試過這個嗎?
viewDidLoad() {
let value = UIInterfaceOrientation.Portrait.rawValue
UIDevice.currentDevice().setValue(value, forKey: "orientation")
shouldAutorotate()
}
0
您是否嘗試過在提交viewController之前設置設備方向?
NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
[[UIDevice currentDevice] setValue:value forKey:@"orientation"];
,然後覆蓋在你的 「介紹」 的viewController的shouldAutorotate方法並返回NO:
-(BOOL)shouldAutorotate
{
return NO;
}
或斯威夫特:
let value = UIInterfaceOrientation.Portrait.rawValue
UIDevice.currentDevice().setValue(value, forKey: "orientation")
和
override func shouldAutorotate() {
return false
}
你會看到一個旋轉的動畫,但它適用於我的應用程序。
試過但沒有成功... – Slavcho