我有一个使用WKWebView的索引html,我使用子视图将其加载到主视图中。它在Swift中。它在portraight中显示正常。它在横向时显示不正确。有没有办法告诉子视图需要调整大小。我还添加了一些旋转代码,但它没有用。
//This lock of code is in viewDidLoad
theWebView = WKWebView(frame: CGRect(x: 0.0, y: 0, width: 375, height: 667))
theWebView!.loadHTMLString(content!, baseURL: url)
self.view.addSubview(theWebView!)
NSNotificationCenter.defaultCenter().addObserver(self, selector: "checkOrientation", name: UIDeviceOrientationDidChangeNotification, object: nil)
}
func checkOrientation()
{
if(UIDeviceOrientationIsLandscape(UIDevice.currentDevice().orientation))
{
println("landscape")
theWebView = WKWebView(frame: CGRect(x: 0.0, y: 0.0, width: 667, height: 375))
}
if(UIDeviceOrientationIsPortrait(UIDevice.currentDevice().orientation))
{
println("portraight")
theWebView = WKWebView(frame: CGRect(x: 0.0, y: 25, width: 375, height: 667))
}
}