4

I have a uiviewcontroller which loads a uiwebview. When the uiviewcontroller loads the uiwebview everything is done correctly. But when one navigates away and returns back and the uiwebview is not loaded, it is displayed differently. The uiwebview scrollview's contentsize height changes by 64px, it gets higher.

When it is loaded for the first it looks like this enter image description here

When one returns back to the view, this is what happens

enter image description here

I hope I was able to make my problem understandable. If more details are necessary, I am able to give more. Thank you

BCI
  • 465
  • 6
  • 19
  • 1
    Did you find a solution to this? I have the same problem when I press the home button and go back to my app. Then I get the same contentSize change as you get. – Thermometer Nov 28 '13 at 08:39
  • 1
    @Thermometer I could fix it, but not in a clean way. The appearance is not as awful anymore, because there isn't this empty space between navigationBar and uiWebView. Still the scrollbar does not touch the navigationBar. – BCI Nov 29 '13 at 10:18
  • I am sure this can be solved in a better way, but this is the code I used for this is - (void)scrollViewDidScroll:(UIScrollView *)aScrollView { if(aScrollView.contentOffset.y < 0) { [aScrollView setContentOffset:CGPointMake(0, 0)]; } else { [aScrollView setContentOffset: CGPointMake(0, aScrollView.contentOffset.y)]; } } – BCI Nov 29 '13 at 10:20
  • @Thermometer have you found any fix? can you please share it – dev4u Feb 25 '14 at 10:00
  • My fix was not really a fix :(. I loaded my `UIWebView` in my `UIViewController`'s view in a `UITabbarController` before. I now load it in a `UIViewController` that I show modally, which fixes the problem for me. I have asked a question about this [here](http://stackoverflow.com/questions/20262938/uiwebview-changes-contentsize-on-ios-7-after-coming-back-from-background), which didn't really get a valid answer, so I just restructured it to fix the problem. – Thermometer Feb 25 '14 at 15:15
  • Here is another discussion of the issue: http://stackoverflow.com/questions/18947872/ios7-added-new-whitespace-in-uiwebview-removing-uiwebview-whitespace-in-ios7 – ThomasW Apr 03 '14 at 05:20

2 Answers2

2

I had a similar problem, try this code in your viewDidLoad method.

if([self respondsToSelector:@selector(setAutomaticallyAdjustsScrollViewInsets:)])
    self.automaticallyAdjustsScrollViewInsets = NO;
Jun
  • 3,422
  • 3
  • 28
  • 58
-1

You can do like this.
- (void) viewDidLoad { [super viewDidLoad]; self.automaticallyAdjustsScrollViewInsets = NO; }