键盘无法在网络视图中正确显示-横向模式

时间:2019-03-07 07:31:13

标签: ios swift webview landscape

我正在呈现这样的自定义Web视图。

let vc = CustomWebViewVC.viewController()
    vc.delegate = self
    present(vc, animated: true, completion: nil)

我已经实现了此功能,以横向模式显示自定义Web视图。

override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation {
    return .landscapeRight
}

//----------------------------------------------------------

override var shouldAutorotate: Bool {
    return false
}

问题

CustomWebViewVC可以在横向模式下正确打开,但是当我单击webivew内的文本字段时会发生这种情况。

enter image description here

我不知道问题是什么。

有什么建议吗?

2 个答案:

答案 0 :(得分:0)

viewDidLoad

中添加以下代码

雨燕4

let value = UIInterfaceOrientation.landscapeLeft.rawValue
UIDevice.current.setValue(value, forKey: "orientation")

答案 1 :(得分:0)

缺少的方法是这个

override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
    return UIInterfaceOrientationMask.landscapeRight
}

在视图控制器中添加此技巧后就可以了。

要以横向模式打开ViewController,您需要像我一样实现这三种方法。

override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation {
    return .landscapeRight
}

//----------------------------------------------------------

override var shouldAutorotate: Bool {
  return false
}

override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
    return UIInterfaceOrientationMask.landscapeRight
}