我已经以编程方式创建了UIWebView。现在,我想以编程方式将其方向设置为(横向或纵向)。请任何人告诉我我该怎么做?谢谢
import UIKit
class ViewController: UIViewController, UIWebViewDelegate {
override func viewDidLoad() {
super.viewDidLoad()
let webV:UIWebView = UIWebView(frame: CGRectMake(0, 0, UIScreen.mainScreen().bounds.width, UIScreen.mainScreen().bounds.height))
webV.loadRequest(NSURLRequest(URL: NSURL(string: "http://tune.tv/humtv-live-embed")!))
webV.delegate = self;
self.view.addSubview(webV)
}
}
在您的viewDidAppear中添加以下内容:
override func viewDidAppear(animated: Bool) {
let value = UIInterfaceOrientation.LandscapeRight.rawValue
UIDevice.currentDevice().setValue(value, forKey: "orientation")
}
Swift 3.0:
override func viewDidAppear(_ animated: Bool) {
let value = UIInterfaceOrientation.landscapeRight.rawValue
UIDevice.current.setValue(value, forKey: "orientation")
}
只需选择您的方向,它将在显示WebView时设置为该方向。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句