提出我有一個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
}
你會看到一個旋轉的動畫,但它適用於我的應用程序。
相關問題
- 1. 如何更改viewController支持的方向?
- 2. ViewController方向更改
- 3. 鎖定ViewController的方向
- 4. UIBarButtonItem更改viewController的方向
- 5. 如何以面向對象的方式重用此ViewController代碼?
- 6. 如何禁用UINavigationController上的縱向方向rootViewController
- 7. 禁用方向但檢測方向
- 8. appdelegate如何調用viewcontroller的方法?
- 9. 使UIView與它的viewController的方向旋轉
- 10. ViewController禁用交互 - iOS
- 11. ObjC禁用ViewController旋轉
- 12. 在Swift中禁用ViewController
- 13. swift中的viewController的鎖定方向
- 14. 如何在方向更改上顯示新的ViewController?
- 15. 如何更改Xcode中特定ViewController的方向
- 16. 如何更改PopViewController上ViewController的動畫方向
- 17. Segue IOS7錯誤的ViewController方向
- 18. 更改ViewController的轉換方向?
- 19. 如何僅在Android活動中禁用反向屏幕方向
- 20. 爲UICollectionView禁用RTL方向
- 21. 禁用屏幕方向
- 22. 禁用方向更改 - WindowManager
- 23. 禁用方向變化
- 24. 如何禁用相同ViewController中的特定UITextField的鍵盤?
- 25. 禁用方向,如果設備是iPhone
- 26. 如何從ViewController調用按鈕方法?
- 27. 如何禁用橫向導向?
- 28. 如何禁用ViewController解除從左到右的滑動?
- 29. 在NavigationController中禁用ViewController的旋轉
- 30. 禁用底層ViewController中的UIGestureRecognizers
試過但沒有成功... – Slavcho