如何在Swift中以编程方式更改UIWebView方向
我以编程方式创build了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") }
只要select你的方向,当WebView被显示时,它将被设置为它。
- iOS快速从另一个数组中删除数组的元素
- advertisingIdentifier和identifierForVendor返回“00000000-0000-0000-0000-000000000000”
- epub阅读器来处理大的html文件
- 转换NSString-> NSDate?
- CIDetctor始终保持无效,无法读取QRCode
- MKOverlayView和触摸
- 我可以序列化一个RealmObject到JSON或Swift的Realm中的NSDictionary?
- UILocalNotification repeatInterval 20天
- 如何使UITextView文本全部可选,并向用户iPhone应用程序显示复制选项?