简体   繁体   English

设备方向更改时,UIWebview中出现黑条

[英]Black bar appearing in UIWebview when device orientation changes

I have a UIWebView that I am loading onto another view, everthing looks fine in portrait or landscape when rotating, however when I am in portrait and I zoom in slightly with pinch or double tap when I rotate from portrait to landscape the view dosnt fill completely with the uiwebview, there are about 10pxls on the right that turn black as outlined in this screen shot. 我有一个UIWebView,我正在加载到另一个视图,旋转时在纵向或横向看起来很好,但是当我在肖像时,当我从纵向旋转到横向时,我用捏或双击轻微放大视图dosnt填充完全在uiwebview中,右侧有大约10pxls,如本屏幕截图所示变为黑色。

在此输入图像描述

if you look carefully you can see the outline of the scroll indicator in the black, which segests this is part of the uiwebview?? 如果仔细观察,你可以看到黑色滚动指示器的轮廓,这是uiwebview的一部分? if so then why dose it turn black in this area. 如果是这样的话,那么为什么它会在这个区域变黑。

Also heres another screen shot of the webview scrolled up abit so you can see its part of the uiwebview... 另外还有另一个webview的屏幕截图向上滚动升技,这样你就可以看到uiwebview的一部分......

在此输入图像描述

This is how I am adding the view onto the detail view. 这就是我将视图添加到详细视图的方式。

- (void)viewdidload
//..

//Load in FirstView
    firstView = [[FirstMainViewController alloc] init];
    firstView.view.frame = CGRectMake(0.0, 0.0, firstView.view.bounds.size.width, firstView.view.bounds.size.height);

    firstView.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

    firstView.view.backgroundColor = [UIColor whiteColor];

    [self.view insertSubview:firstView.view belowSubview:actionTabBar]; 

//..

Try to set the background of the webView transparent (clearColor) and set it's opaque property to FALSE. 尝试设置webView透明(clearColor)的背景,并将其opaque属性设置为FALSE。 Then make the background white in your html or simply have the view beneath the webView white. 然后在html中将背景设为白色,或者只是将视图置于webView白色下方。

I had the same problem, and simply setting opaque to NO fixed it. 我遇到了同样的问题,只是将opaque设置为NO修复它。 Didn't even have to change the background color, it works fine with the background color set to white. 甚至没有更改背景颜色,它可以正常工作,背景颜色设置为白色。

I put in the line... 我加入了......

webView.scrollView.backgroundColor = UIColor.whiteColor()

webView is my @IBOutlet weak var webView: UIWebView! webView是我的@IBOutlet弱变量webView:UIWebView!

Turn off WebKitDiskImageCacheEnabled and the black border goes away : 关闭WebKitDiskImageCacheEnabled ,黑色边框消失:
In applicationDidFinishLaunchingWithOptions add the following lines : applicationDidFinishLaunchingWithOptions添加以下行:

[[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"WebKitDiskImageCacheEnabled"];
[[NSUserDefaults standardUserDefaults] synchronize];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM