ios - UIWebBrowserView 不跨越整个 UIWebView

标签 ios iphone layout 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 的 subview :http://normansoven.com/ios-webview/#.VHyOUr6Jnww但从未见过 webBrowserView。

Teh 代码:

- (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, 0, self.view.frame.size.width, 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 的属性 automaticallyAdjustsScrollViewInsetsUIViewController 引用说:

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 框架或添加了自动布局约束,UIViewController 也会将顶部间隙添加到 UIWebView 的 ScrollView 中。要克服这种行为,只需

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.

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

任何 ScrollView 都有同样的问题,即 Blank space at top of UITextView in iOS 10 https://stackoverflow.com/search?q=automaticallyAdjustsScrollViewInsets

关于ios - UIWebBrowserView 不跨越整个 UIWebView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27159931/

相关文章:

ios - 是否可以在 microsoft-edge 浏览器中从 ios 平台打开 ionic cordova 应用程序的链接

ios - 如何在 iOS swift 中从 Firebase 远程配置获取整数值?

iphone - 正确使用 Grand Central Dispatch - 启动、挂起、恢复、取消线程?

java - 我想通过单击添加按钮动态添加 JLabel 和文本框

objective-c - AFNetworking HTTPRequestOperation 需要从完成 block 设置数组,但这不起作用?

ios - 动画约束正在打破其他约束

iphone - KalViewController View 为黑色

ios - 使用 AudioQueue 播放 PCM 音频流音量小

javascript - Html5/Javascript对接/流程部分布局

html - 如何为一个div添加滚动条,2个div始终可见