简体   繁体   中英

UIWebView auto size in landscape (Swift)

i'm new to the Swift programming language!

I'm building a simple app that shows a webpage, my problems is, when i rotate the device, the WebView isn't sized to fill the Scene...

I've tried to use this code:

func resizeWebView(){

    webView.scalesPageToFit = true
    webView.contentMode = UIViewContentMode.ScaleToFill
    webView.multipleTouchEnabled = true
    webView.autoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight
    self.view.addSubview(webView)

}

i call this function on the viewDidLoad() function, is that right?

Are there anyway to do this? Everything that i found on the internet is for Objective-C...

Thanks :)

I just did a simple example:

import UIKit
import WebKit

class ViewController: UIViewController {

    @IBOutlet var containerView : UIView?
    var webView: WKWebView?

    override func loadView() {
        super.loadView()

        self.webView = WKWebView()
        self.view = self.webView!
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        var url = NSURL(string:"http://chart.finance.yahoo.com/z?s=AAPL&t=6m&q=l&l=on&z=s&p=m50,m200")
        var req = NSURLRequest(URL:url)
        self.webView!.loadRequest(req)
    }
}

I did not use auto layout or deal with status bar issues, but no problem resizing on rotation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM