2
我的整个应用程序都在portrait
模式下。我只想在landscape
模式下使用一个视图控制器(左图)。以编程方式更改方向无法正常工作
func application(application: UIApplication, supportedInterfaceOrientationsForWindow window: UIWindow?) -> UIInterfaceOrientationMask
{
if let _navigationController = window?.rootViewController as? UINavigationController {
if _navigationController.topViewController is FullScreenPlayerVC {
return UIInterfaceOrientationMask.LandscapeLeft
}
}
return UIInterfaceOrientationMask.Portrait
}
这是我的控制器A
override func shouldAutorotate() -> Bool
{
return true
}
override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask
{
return UIInterfaceOrientationMask.Portrait
}
现在我把控制器B.这是我的控制器B
override func viewDidAppear(animated: Bool)
{
super.viewDidAppear(animated)
let value = UIInterfaceOrientation.LandscapeLeft.rawValue
UIDevice.currentDevice().setValue(value, forKey: "orientation")
}
override func shouldAutorotate() -> Bool
{
return true
}
override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask
{
return UIInterfaceOrientationMask.Landscape
}
它可以按我的要求时,我把控制器B同时举行我的设备处于肖像模式,但是如果我已将手机搁置在横向模式中。
它不执行所需的操作。搜索了很多关于它的信息,但还没能找到解决方案。
我已经尝试了许多解决方案,但没有正常工作。
后取向的变化问题只是用下面的代码,内部代码不需要DidAppear。覆盖func supportedInterfaceOrientations() - > UIInterfaceOrientationMask { return .Landscape } –
试过这个,但很有用的不幸:( – kashifasif