gpt4 book ai didi

ios - WebView 内容未正确缩放

转载 作者:行者123 更新时间:2023-11-29 01:30:38 25 4
gpt4 key购买 nike

我正在尝试在 UIWebView 中加载一些内容,但它没有正确显示。我在 webview 周围画了一条红边,它的位置是正确的。但正如您所见,内容上方有一个灰色条。

Arghh webviews

我的 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];

}

谁能告诉我在这种情况下我做错了什么?谢谢

最佳答案

试试这个

self.automaticallyAdjustsScrollViewInsets = NO;

在你的viewDidLoad

编辑:

以上答案不适用于 iOS9

solution from NKorotkov作品:

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;

}

关于ios - WebView 内容未正确缩放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33504598/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com