Added whitespace in UIWebview - removing UIWebView whitespace in iOS7 & iOS8

前端 未结 6 2074
鱼传尺愫
鱼传尺愫 2020-12-13 18:43

Im loading local html files, since iOS7 there is added white space on top in the UIWebView.(I cant post an image as i do not have enough points.) image can be seen here- sna

6条回答
  •  轮回少年
    2020-12-13 19:14

    This problem only affects the UIWebView if it is the first subview of the parent view. One alternative way to work around this problem is to add another non-visible empty view to the parent view as the first view. In Interface Builder add a zero size subview and use the Editor->Arrange->Send to Back menu command.

    If you're not using Interface Builder, but instead are subclassing the UIWebView, then it can be done by creating a UIView instance variable called scrollFixView and overriding the following methods:

    - (void)didMoveToSuperview
    {
      [super didMoveToSuperview];
    
      if ([self superview].subviews.firstObject == self) {
        _scrollFixView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
        _scrollFixView.hidden = YES;
        [[self superview] insertSubview:_scrollFixView belowSubview:self];
      }
    }
    
    - (void)removeFromSuperview
    {
      if (_scrollFixView) {
        [_scrollFixView removeFromSuperview];
        _scrollFixView = nil;
      }
    
      [super removeFromSuperview];
    }
    

提交回复
热议问题