【问题标题】:How to forcefully Call webview in landscape mode in swift3 ios如何在swift3 ios中以横向模式强制调用webview
【发布时间】:2017-10-18 02:13:36
【问题描述】:

我希望我的一个包含 webview 的视图控制器每次都以横向模式出现。我写过这样的代码

导入 UIKit 导入 WebKit

类 DrawWebViewController: UIViewController{

@IBOutlet var scrollView: UIScrollView!

@IBOutlet var webView: UIWebView!

// var webAView: WKWebView?

override func loadView() {
    super.loadView()
   // resizeWebView()

}

/* func resizeWebView(){

    webView.scalesPageToFit = true
    webView.contentMode = UIViewContentMode.scaleToFill
    webView.isMultipleTouchEnabled = true
    webView.autoresizingMask = UIViewAutoresizing.flexibleWidth
    self.view.addSubview(webView)

}*/

    var newUrlVal = "http://wonderhomes.co/draw.php?id=bedroom"
override func viewDidLoad() {
    super.viewDidLoad()

    if let url = URL (string: newUrlVal){
        let requestObj = URLRequest(url: url)
        _ = webView.loadRequest(requestObj)

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

    //Image for logo at navigation bar
    let logo = UIImage(named: "logo-250-by-60---1.png")
    let imageView = UIImageView(image:logo)
    self.navigationItem.titleView = imageView

    // Do any additional setup after loading the view.
}
private func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
    return UIInterfaceOrientationMask.landscapeLeft
}
private func shouldAutorotate() -> Bool {
    return false
}
/*
// MARK: - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    // Get the new view controller using segue.destinationViewController.
    // Pass the selected object to the new view controller.
}
*/

}

任何人都可以建议我可以进行哪些更改以在横向模式下调用 webview。

【问题讨论】:

    标签: ios swift xcode webview orientation


    【解决方案1】:

    我得到了答案 -

    1. 如果你只想旋转 webview 然后使用 -

    myWebView?.transform=CGAffineTransform(rotationAngle: CGFloat(Double.pi/2))

    1. 如果你想在横向模式下查看控制器 -

    让值 = UIInterfaceOrientation.landscapeRight.rawValue UIDevice.current.setValue(value, forKey: "orientation")

    将上面的行写在你想要的地方。

    【讨论】:

      【解决方案2】:

      只需在 ViewController 的 viewDidAppear 方法中调用以下方法即可。

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

      并让所有代码保持不变。

      【讨论】:

      • 但之后它也不会进入横向模式
      猜你喜欢
      • 2012-02-14
      • 1970-01-01
      • 1970-01-01
      • 2019-03-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多