UIWebView content not adjusted to new frame after rotation

前端 未结 2 363
情话喂你
情话喂你 2021-01-22 14:22

I have an e-mail application,
which shows the content in an UIWebView inside an UISplitViewController.
Everything works fine until i rotate the

2条回答
  •  离开以前
    2021-01-22 15:14

    This seems to be a bug also in iOS 7 and iOS 8. A fix would be this:

    First resize the frame on layout changes:

    - (void)viewDidLayoutSubviews {
        [super viewDidLayoutSubviews];
        _webView.frame = self.view.bounds;
    }
    

    Then on the rotation callback reset the zoomScale to 0. Yes, 0!

    - (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
        // Allow the animation to complete
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [_webView.scrollView setZoomScale:0 animated:YES];
        });
    }
    

    You can also use the new function

    - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id)coordinator {
        // Allow the animation to complete
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [_webView.scrollView setZoomScale:0 animated:YES];
        });
    }
    

提交回复
热议问题