UIWebBrowserView不跨越整个UIWebView [英] UIWebBrowserView does not span entire UIWebView
问题描述
所以我一直试图让这个简单的行为在我的iPhone应用程序上运行一段时间。我的顶部有一个导航栏,底部有一个标签栏。我正在webview中加载我的所有内容,我想在两者之间加入。我已经两次发布了这个问题,
So I have been trying to get this simple behavior working on my iPhone app now for a while. I have a nav bar at the top and a tab bar at the bottom. I am loading all of my content in a webview, which I want to fit between the two. I have posted about this issue twice already,
这里:以编程方式设置内容以填充标签栏和导航栏之间的屏幕控制器
目前,我的webview看起来并且在iPhone 4和4s上运行良好,问题出现在5s上。当屏幕完成加载时,它看起来像这里的图像: http://grosh.co/screen.jpg。这在模拟器和设备上都会发生。
Currently, my webview looks and performs fine on iPhone 4 and 4s, the issue arises on the 5s. When the screen finishes loading, it looks like the image here: http://grosh.co/screen.jpg . This occurs on both the simulator as well as devices.
经过进一步检查,我发现UIWebView实际上正确地跨越(你看到的灰色区域是webview) 。较小的内容实际上是 UIWebBrowserView ,我很难找到任何信息。
Upon further inspection, I discovered that the UIWebView is in fact spanning correctly (the grey areas you see are the webview). The smaller content is actually a UIWebBrowserView, which I am having a hard time finding any information on.
我有我在下面使用的代码,以及日志输出,以确保所有数字都正确。我的问题是,
I have the code I am using below, as well as a log output to insure all the numbers are correct. My questions are,
1)有没有更好的方法将webview设置为跨越所有设备的顶部和底部栏之间的屏幕区域?
1) Is there a better way to set the webview to span the screen area between the top and bottom bars for all devices?
2)如果没有,有没有办法将UIWebBrowser设置为跨越整个webview?
2) If not, is there a way to set the UIWebBrowser to span the entire webview?
我尝试迭代子视图如下所述的webview: http://normansoven.com/ios-webview/#.VHyOUr6Jnww 但是从未见过webBrowserView。
I tried iterating over the subviews of the webview as described here: http://normansoven.com/ios-webview/#.VHyOUr6Jnww but the webBrowserView was never seen.
Teh Codez:
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, 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
Log output, from an 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
参考说:
I've encountered with the same problem.
And found simple fix.
The culprit is UIViewController
's property automaticallyAdjustsScrollViewInsets
. UIViewController
reference says:
默认值为
YES
,它允许视图控制器调整其
滚动视图插入以响应
状态栏,导航栏和工具栏或标签栏消耗的屏幕区域。
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.
这意味着 UIViewController
将最大差距添加到 UIWebView
的滚动视图,即使您正确设置了webview框架或添加自动布局约束。要克服这种情况,只需
It means that UIViewController
adds that top gap to UIWebView
's scroll view even if you properly set up webview frame or add autolayout constraints. To overcome this behaviour just
如果你想要
,设置为否
自己管理滚动视图插入调整,例如当
在视图层次结构中有多个滚动视图时。
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.
管理滚动视图插入调整你的自我在我们的上下文中意味着我们不会添加任何插入内容;)
"manage scroll view inset adjustments your self" in our context means that we won't add any insets ;)
与任何滚动相同的问题查看,即 UITextView顶部的空白区域iOS 10
https://stackoverflow.com/search?q=automaticallyAdjustsScrollViewInsets
same issue with any scroll view, i.e. Blank space at top of UITextView in iOS 10 https://stackoverflow.com/search?q=automaticallyAdjustsScrollViewInsets
这篇关于UIWebBrowserView不跨越整个UIWebView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!