Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/113.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在方向被另一个(iOS)强制横向调整后,如何恢复UIViewController的正确方向?_Ios_Swift_Uiinterfaceorientation_Interface Orientation - Fatal编程技术网

在方向被另一个(iOS)强制横向调整后,如何恢复UIViewController的正确方向?

在方向被另一个(iOS)强制横向调整后,如何恢复UIViewController的正确方向?,ios,swift,uiinterfaceorientation,interface-orientation,Ios,Swift,Uiinterfaceorientation,Interface Orientation,我遇到的问题有点奇怪,我似乎找不到任何好的解决办法。所以我有两个UIViewController,一个可以接受所有方向,另一个只能在横向视图中查看 internal override func shouldAutorotate() -> Bool { return true } internal override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask { return

我遇到的问题有点奇怪,我似乎找不到任何好的解决办法。所以我有两个UIViewController,一个可以接受所有方向,另一个只能在横向视图中查看

internal override func shouldAutorotate() -> Bool {
    return true
}

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

如果我在ViewController1上处于纵向模式,并且我按下VC2,它旋转的很好,但当我离开VC2时,VC1被卡在横向模式中,即使设备本身处于纵向模式。我怎样才能修好它?我尝试在VC1的ViewDidDisplay方法中调用AttemptToRotateTodevicoOrientation方法,但它不起任何作用

您只需要在视图控制器中创建应用程序代理实例,如:

let appDel = UIApplication.shared.delegate as! AppDelegate
在视图控制器的ViewWillAspect()上,只需为横向添加以下代码

appDel.myOrientation = .landscape
UIDevice.current.setValue(UIInterfaceOrientation.landscapeLeft.rawValue, forKey: "orientation")
对于肖像,请添加此代码

appDel.myOrientation = .portrait
UIDevice.current.setValue(UIInterfaceOrientation.portrait.rawValue, forKey: "orientation")

你可以查一下:@mamun999你可能误解了我。我不是在问我如何才能强制定向,我的解决方案已经奏效了。我问的是如何解决它的副作用,这不是我所需要的。我需要每个控制器有自动旋转到所有方向,但其中一个是唯一的景观。我通过我的解决方案得到了这一点,但由于某些原因,以前的控制器卡在了横向中。好吧,只要在需要横向的任何地方做一件事就可以添加此代码
appDel.myOrientation=.scape UIDevice.current.setValue(UIInterfaceOrientation.landscapeLeft.rawValue,forKey:“方向”)
离开该屏幕时,将旋转设置为各个方面。