ios - 如何在swift3 ios中以横向模式强制调用webview

标签 ios swift xcode webview orientation

我希望我的一个包含 webview 的 View Controller 每次都以横向模式出现。我写过这样的代码

导入 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。

最佳答案

我得到了我的答案-

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

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

  1. 如果你想在横向模式下查看 Controller -

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

在你想要的地方写上一行。

关于ios - 如何在swift3 ios中以横向模式强制调用webview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44044786/

相关文章:

xcode - 无法在 Xcode 中拖动(以生成代码片段)

ios - 如何在 Objective-C 中将 AVAudioPCMBuffer 转换为 NSData?

SceneKit 中的 iOS 自定义几何

swift - 如何将数据从AddController传递到UITableViewController

xcode - Phonegap 2.1 支持 Iphone 5 显示

ios - 用Textfield与键盘一起向上移动Uitoolbar

android - 在封闭的 WiFi 网络(无互联网连接)上向 iOS/Android 发送推送通知

ios - UITableView 文本覆盖我的自定义部分标题?

ios - 如何将 MKMapItem 转换为二进制数据存储在 Core Data 中?

ios - 以编程方式将模糊图像背景添加到 xib