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 UIWebView的强制横向定位?_Ios_Swift_Uiwebview_Swift2_Landscape - Fatal编程技术网

Ios UIWebView的强制横向定位?

Ios UIWebView的强制横向定位?,ios,swift,uiwebview,swift2,landscape,Ios,Swift,Uiwebview,Swift2,Landscape,我有一个应用程序,其中所有视图都是肖像,但只有一个视图是加载PDF的UIWebView,需要在景观中 我的项目设置如下: 我尝试了以下方法: override func shouldAutorotate() -> Bool { return false } override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask { let orientation: UIInter

我有一个应用程序,其中所有视图都是肖像,但只有一个视图是加载PDF的UIWebView,需要在景观中

我的项目设置如下:

我尝试了以下方法:

 override func shouldAutorotate() -> Bool {
    return false
 }

override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
    let orientation: UIInterfaceOrientationMask = [UIInterfaceOrientationMask.Landscape, UIInterfaceOrientationMask.LandscapeLeft]
    return orientation
}
上面的代码似乎不起作用。我通过网上搜索得到了密码。我不确定我做错了什么。任何建议都会有帮助,如果您能提供一些示例代码,那就太好了

我只想强制一个UIWebView的横向定位

编辑:

错误:

如果此处难以读取错误:


受支持的方向与应用程序没有共同的方向,[KM\u T\u World.MainViewController shouldAutorotate]返回YES'

在您的视图控制器中实现这一点:

override func viewDidLoad() {
    super.viewDidLoad()
    UIViewController.attemptRotationToDeviceOrientation()
}

override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
    return [UIInterfaceOrientationMask.LandscapeLeft, UIInterfaceOrientationMask.LandscapeRight]
}
使用以下代码:

override func viewDidAppear(animated: Bool) {
    let value = UIInterfaceOrientation.LandscapeLeft.rawValue
    UIDevice.currentDevice().setValue(value, forKey: "orientation")
}
override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask{

    return UIInterfaceOrientationMask.Portrait
}
您的设备方向应为:

结果:

更多信息

更新:

通过添加以下代码,可以简单地锁定特定视图的方向:

override func viewDidAppear(animated: Bool) {
    let value = UIInterfaceOrientation.LandscapeLeft.rawValue
    UIDevice.currentDevice().setValue(value, forKey: "orientation")
}
override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask{

    return UIInterfaceOrientationMask.Portrait
}

谢谢你的回答。但是它仍然以纵向显示。@user2190986您应该在
Info.plist
中为整个应用程序打开横向。然后它就起作用了。根据您拥有的ViewController数量和希望仅纵向的ViewController数量,我建议在ViewController中实现仅纵向的修复,或扩展整个类以实现所需的行为。谢谢您的回复。如何进行人像修正?是否与上述内容相同,只需将横向更改为纵向?@user2190986是的,只需
返回UIInterfaceOrientationMask.纵向
非常感谢您的回复。我已经对我的问题做了修改,你能告诉我这是否正确吗。我正在尝试打开info.plist中的风景。谢谢你的回答。您的答案是可行的,但唯一的问题是,通过在Xcode设置中打开设备方向至横向,用户可以旋转设备并更改应用程序中所有视图的方向。我只想展示一幅风景画,剩下的是肖像画。谢谢你的回复。你的最新答案很有效。但它适用于除UIWebView之外的所有视图。它不会旋转它。我可以很好地旋转所有其他视图,但不能旋转UIWebView。另外,只有在Xcode中选中横向选项时,它才起作用。不要在
UIWebView
控制器中使用
supportedInterfaceOrientations
。但UIWebView控制器是我唯一要旋转到横向的控制器。其他一切都应该是肖像画。任何建议。我感谢所有的帮助。谢谢。请尝试此更新项目: