UIWebView scrollView changed it content offset when status bar hides

1.4k views Asked by At

I have a view in my app (iOS7) where a have such a view controllers hierarchy ViewController->childViewController->childViewController->myChildViewController. myChildViewController has a full sized UIWebView on it. I have a UIButton to hide UIToolBar from one of childViewController. When I press the button - UIWebView scrollView changed its content offset by status bar hide. How to avoid this behavior?

2

There are 2 answers

5
jjv360 On

That should only happen if you've made the UIWebView the main view, such as

viewController.view = webView;

If you make it a subview instead, it should ignore the offsets:

webView.frame = viewController.view.bounds;
webView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight
[viewController.view addSubview:webView];

It may also change if the parent view controller is resized...

Another thing you can try in the view controller that holds the web view:

[viewController setAutomaticallyAdjustsScrollViewInsets:NO];
0
Armands Antans On

Previously mentioned solution works just fine.

[self addSubview:webView];
self.automaticallyAdjustsScrollViewInsets = NO;