1

I'm presenting custom web view like this.

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

I've implemented this to show custom web view in landscape mode.

override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation {
    return .landscapeRight
}

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

override var shouldAutorotate: Bool {
    return false
}

Issue

CustomWebViewVC is correctly opens in landscape mode but when I click on textfield inside of webivew this happens.

enter image description here

I don't know what is the issue is.

Any suggestions?

Mahendra
  • 8,448
  • 3
  • 33
  • 56

2 Answers2

1

The missing method was this

override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
    return UIInterfaceOrientationMask.landscapeRight
}

After adding this in view controller did the trick.

To open viewcontroller in landscape mode you need to implement all three method as I did.

override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation {
    return .landscapeRight
}

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

override var shouldAutorotate: Bool {
  return false
}

override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
    return UIInterfaceOrientationMask.landscapeRight
}
Mahendra
  • 8,448
  • 3
  • 33
  • 56
0

Add following code in viewDidLoad

Swift 4

let value = UIInterfaceOrientation.landscapeLeft.rawValue
UIDevice.current.setValue(value, forKey: "orientation")
Prashant Tukadiya
  • 15,838
  • 4
  • 62
  • 98