UIWebBrowserView does not span entire UIWebView(UIWebBrowserView 不跨越整个 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,
两者都在这里:IOS 视图仍然无法加载在正确的位置
在这里:以编程方式设置内容填满标签栏和导航控制器之间的屏幕
目前,我的 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.
法典:
- (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
的属性automaticallyAdjustsScrollViewInsets
.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
设置为 NO
如果你想要自己管理滚动视图插图调整,例如何时视图层次结构中有多个滚动视图.
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 ;)
任何滚动视图都存在同样的问题,即 iOS 10 中 UITextView 顶部的空白区域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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:UIWebBrowserView 不跨越整个 UIWebView
基础教程推荐
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01