I am fairly new to iOS development and I\'m using a WKWebView
to display a page that plays a video using the Vimeo Player. When the app starts up, it shows the
Can you try this
wkWebView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
I was able to solve this problem by injecting a javascript reload call like this:
Swift:
func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
coordinator.animateAlongsideTransition(nil, completion: {
//Reset Frame of Webview
webView.evaluateJavaScript("location.reload();", completionHandler: nil)
}
Objective C:
-(void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
//Reset Frame of Webview
[_webView evaluateJavaScript:@"location.reload();" completionHandler:^(id _Nullable obj, NSError * _Nullable error) {
NSLog(@"error:%@", error);
}];
}
You don't need to reload the entire web page. You just need to reload its input views. Make sure you have set constraints to web view properly and then add below code while changing orientation.
// Reload inputs so that webview can adjust its content according to orientation
[self.webView reloadInputViews];
After few hours of struggling, this is what worked for me:
<header><meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no, shrink-to-fit=no'></header><body style='margin: 0px; padding: 0px; width:100%; height:100%;'>...
Set width and height of both body and your video element to 100% and disable user scaling through header tag.