ios – UIWebBrowserView不跨越整个UIWebView

所以我一直试图让这个简单的行为在我的iPhone应用程序上运行一段时间.我的顶部有一个导航栏,底部一个标签栏.我正在webview中加载我的所有内容,我想在两者之间加入.我已经两次发布过这个问题,

这两个:IOS View still does not load in the correct position

在这里Programmatically setting content to fill screen between tab bar and nav controller

目前,我的webview看起来并且在iPhone 4和4s上运行良好,问题出现在5s.当屏幕完成加载时,它看起来像这里的图像:http://grosh.co/screen.jpg.这在模拟器和设备上都会发生.

经过进一步检查,我发现UIWebView实际上正确地跨越了(你看到的灰色区域是webview).较小的内容实际上是一个UIWebbrowserView,我很难找到任何信息.

我有我在下面使用的代码,以及日志输出,以确保所有数字都正确.我的问题是,

1)是否有更好的方法将webview设置为跨越所有设备的顶部和底部条之间的屏幕区域?

2)如果没有,有没有办法将UIWebbrowser设置为跨越整个webview?

我尝试迭代webview的子视图,如下所述:http://normansoven.com/ios-webview/#.VHyOUr6Jnww但是webbrowserView从未见过.

Teh Codez:

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view,typically from a nib.    


CGFloat viewheight = self.view.bounds.size.height;
NSLog(@"Height1:%f",viewheight);

CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat viewheight2 = screenRect.size.height;
NSLog(@"Height2:%f",viewheight2);

CGFloat height = self.view.frame.size.height;
NSLog(@"Height3:%f",height);


CGFloat navBarHeight = self.navigationController.navigationBar.frame.size.height;
NSLog(@"NAVHeight:%f",navBarHeight);

CGFloat tabBarHeight = self.tabBarController.tabBar.frame.size.height;
NSLog(@"TABHeight:%f",tabBarHeight);

CGFloat statusbarheight = [UIApplication sharedApplication].statusBarFrame.size.height;
NSLog(@"StatbarHeight:%f",statusbarheight);

CGFloat spacetoRemove = navBarHeight + tabBarHeight + statusbarheight;
    NSLog(@"NAVHeight+TABHeight:%f",spacetoRemove);
CGFloat newHeight = viewheight - spacetoRemove;
        NSLog(@"NewHeight:%f",newHeight);

CGRect frame =  CGRectMake(0,navBarHeight + statusbarheight,self.view.frame.size.width,newHeight);

self.webView = [[UIWebView alloc]initWithFrame:frame];


//self.webView = [[UIWebView alloc] initWithFrame:CGRectMake(0,self.view.frame.size.height)];


[self.view addSubview:self.webView];

self.webView.scalesPagetoFit = true;
NSURL *url = [NSURL URLWithString:@"http://example.com/finnaRoot/index.PHP"];
NSURLRequest *requestURL = [NSURLRequest requestWithURL:url];
[self.webView loadRequest:requestURL];
self.webView.scrollView.showsverticalScrollIndicator = false;


self.navigationItem.titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"logo.png"]];

self.webView.delegate = self;
self.tabBarController.delegate = self;
self.webView.scrollView.delegate = self;

}

来自iPhone 5s的日志输出

2014-11-26 17:19:21.184 Finna[14617:1765689] Height1:568.000000
2014-11-26 17:19:21.185 Finna[14617:1765689] Height2:568.000000
2014-11-26 17:19:21.185 Finna[14617:1765689] Height3:568.000000
2014-11-26 17:19:21.185 Finna[14617:1765689] NAVHeight:44.000000
2014-11-26 17:19:21.185 Finna[14617:1765689] TABHeight:49.000000
2014-11-26 17:19:21.185 Finna[14617:1765689] StatbarHeight:20.000000
2014-11-26 17:19:21.185 Finna[14617:1765689] NAVHeight+TABHeight:113.000000
2014-11-26 17:19:21.186 Finna[14617:1765689] NewHeight:455.000000

解决方法

我遇到过同样的问题.
并找到了简单的修复.
罪魁祸首是UIViewController的属性automaticAdjustsScrollViewInsets. UIViewController参考说:

Default value is YES,which allows the view controller to adjust its
scroll view insets in response to the screen areas consumed by the
status bar,navigation bar,and toolbar or tab bar.

这意味着即使您正确设置了webview框架或添加了autolayout约束,UIViewController也会向UIWebView的滚动视图添加顶部间隙.要克服这种行为

Set to NO if you
want to manage scroll view inset adjustments yourself,such as when
there is more than one scroll view in the view hierarchy.

在我们的上下文中“管理滚动视图插入调整你的自我”意味着我们不会添加任何插入;)

任何滚动视图都存在同样的问题,即Blank space at top of UITextView in iOS 10
https://stackoverflow.com/search?q=automaticallyAdjustsScrollViewInsets

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...