我有一个肖像应用程序,其中一个横向的ViewController。
我一直在研究如何在应用程序锁定为肖像模式时强制将方向设置为横向,并尝试了很多这里以及其他地方提出的解决方案,但到目前为止都没有成功。
到目前为止,我成功地使需要横向旋转的VC自动旋转,但由于方向未被锁定,所有其他VC也会旋转。
我一直在研究如何在应用程序锁定为肖像模式时强制将方向设置为横向,并尝试了很多这里以及其他地方提出的解决方案,但到目前为止都没有成功。
到目前为止,我成功地使需要横向旋转的VC自动旋转,但由于方向未被锁定,所有其他VC也会旋转。
override func viewDidAppear(animated: Bool)
{
let value = UIInterfaceOrientation.LandscapeRight.rawValue
UIDevice.currentDevice().setValue(value, forKey: "orientation")
}
override func shouldAutorotate() -> Bool
{
return true
}
经过一番深入挖掘,我在找到一个示例项目后得出了这个结果,但虽然它在那个项目中可以工作,但对我来说似乎无法工作。
这是在AppDelegate中的。
func application(application: UIApplication, supportedInterfaceOrientationsForWindow window: UIWindow?) -> UIInterfaceOrientationMask {
if self.window?.rootViewController?.presentedViewController is ConclusionReferencesVC {
let conclusionReferencesVC = self.window!.rootViewController!.presentedViewController as! ConclusionReferencesVC
if conclusionReferencesVC.isPresented
{
return UIInterfaceOrientationMask.LandscapeRight;
}
else
{
return UIInterfaceOrientationMask.Portrait;
}
}
else
{
return UIInterfaceOrientationMask.Portrait;
}
}
这是我想要在横向视图中拥有的VC:
var isPresented = true
@IBAction
func dismiss()
{
isPresented = false
self.presentingViewController!.dismissViewControllerAnimated(true, completion: nil);
}
由于某种原因,supportedInterfaceOrientationsForWindow方法无法验证初始条件。
我还尝试了其他方法,但都没有成功:
Swift 2.0中的supportedInterfaceOrientationsForWindow
有什么想法吗?似乎我漏掉了什么,但我想不出来是什么。