【发布时间】:2015-01-25 10:00:56
【问题描述】:
所以一段时间以来,我一直试图让这个简单的行为在我的 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。
法典:
- (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
【问题讨论】:
-
所以最新的 iOS 更新修复了这个问题,这让我相信这是一个错误。有机会时,我将添加我在下面使用的解决方法代码。它起作用了,应用程序被商店接受了。
标签: ios iphone layout uiwebview