gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 10:13:57 25 4
gpt4 key购买 nike

我希望我的一个包含 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com