我以为我已经解决了这个问题,但显然没有。我正在使用下面的代码来设置Web视图,使其显示在顶部的导航栏和底部的选项卡栏之间。这发生在我的viewDidLoad()方法中。在我测试过的所有模拟器上,它都运行良好,但是当我测试朋友的运行7.1.1的iPhone 4s时,Web视图呈现在屏幕的整个高度上,由顶部导航栏和底部选项卡栏覆盖。
如何在7以上的所有设备和操作系统上获得所需的行为?
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/notifications.php"];
NSURLRequest *requestURL = [NSURLRequest requestWithURL:url];
[self.webView loadRequest:requestURL];
self.webView.scrollView.showsVerticalScrollIndicator = false;
self.navigationController.navigationBar.titleTextAttributes = @{UITextAttributeTextColor : [UIColor whiteColor]};
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.webView.delegate = self;
self.webView.scrollView.delegate = self;
最佳答案
这是因为您跨越了整个视图
在您的矩形中,您需要减去制表符和导航栏的高度和宽度
看这个例子
- (void)viewDidLoad {
[super viewDidLoad];
CGFloat viewheight = self.view.frame.size.height;
CGFloat navBarHeight = self.navigationController.navigationBar.frame.size.height;
CGFloat tabBarHeight = self.tabBarController.tabBar.frame.size.height;
CGFloat spaceToRemove = navBarHeight + tabBarHeight;
CGFloat newHeight = viewheight - spaceToRemove;
NSLog(@"%f",newHeight);
NSLog(@"%f",self.view.frame.size.height);
CGRect frame = CGRectMake(0 , 0 + navBarHeight, self.view.frame.size.width, newHeight);
UIView *newView = [[UIView alloc]initWithFrame:frame];
newView.backgroundColor = [UIColor redColor];
[self.view addSubview:newView];
}
关于ios - iOS View仍无法正确加载,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27083413/