我正在尝试在UIWebView中加载一些内容,但它没有正确显示。 我在webview周围画了一条红色边缘,并且位置正确。但正如您所看到的,内容上面有一个灰色条。
我在viewDidLoad webview中有以下代码:
productEnergyDetailWebview = [[UIWebView alloc]init];
productEnergyDetailWebview.delegate = self;
productEnergyDetailWebview.scalesPageToFit = YES;
productEnergyDetailWebview.opaque = YES;
[productEnergyDetailWebview setUserInteractionEnabled:true];
productEnergyDetailWebview.autoresizesSubviews = YES;
productEnergyDetailWebview.scrollView.bounces = false;
productEnergyDetailWebview.scrollView.scrollEnabled = false;
更多代码:
- (void)webViewDidFinishLoad:(UIWebView *)webView {
[topBar removeFromSuperview];
[self createViews];
[productEnergyDetailWebview setScalesPageToFit:YES];
[refreshIndicator stopAnimating];
[refreshIndicator removeFromSuperview];
[productEnergyDetailWebview setHidden:false];
}
-(void)createViews{
productEnergyDetailWebview.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
if(selectedRange != 5 && selectedRange != 4){
//Add the bar above the detailWebView
[self createTopBar];
int xLocation = topBar.frame.size.height + topBar.frame.origin.y;
[productEnergyDetailWebview setFrame:CGRectMake(self.view.frame.origin.x, xLocation, self.view.frame.size.width, (self.view.frame.size.height - xLocation) - 50)];
[productEnergyDetailWebview setScalesPageToFit:YES];
[productEnergyDetailWebview setContentMode:UIViewContentModeScaleAspectFill];
}
productEnergyDetailWebview.scrollView.bounces = false;
productEnergyDetailWebview.scrollView.scrollEnabled = false;
[productEnergyDetailWebview setUserInteractionEnabled:true];
}
在这种情况下,谁能告诉我我做错了什么?谢谢
答案 0 :(得分:1)
试试这个
self.automaticallyAdjustsScrollViewInsets = NO;
在viewDidLoad
编辑:
上面的答案在iOS9上不起作用
if (__iOS_9_OR_GREATER__) {
CGFloat topInset = 20;
if (self.navigationController) {
topInset += self.navigationController.navigationBar.bounds.size.height;
}
UIEdgeInsets insets = UIEdgeInsetsMake(topInset, 0, 0, 0);
self.collectionView.contentInset = insets;
self.collectionView.scrollIndicatorInsets = insets;
}