如何在 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]};[超级viewDidLoad];//在加载视图后做任何额外的设置,通常是从笔尖.self.webView.delegate = self;self.webView.scrollView.delegate = self; 解决方案 这是因为你要跨越整个视图在您的矩形中,您需要减去标签和导航栏的高度和宽度看看这个例子- (void)viewDidLoad {[超级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];}I thought I had this cleared up but apparently not. I am using the code below to set a webview to appear between the top nag bar and tab bar at the bottom. This happens in my viewDidLoad() method. It was working fine on all simulators I had tested it on, however when I tested a friend's iPhone 4s running 7.1.1 the webview rendered spanning the entire height of the screen, covered by both the top nag bar and bottom tab bar.How to I get the desired behavior across all devices and OS above 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; 解决方案 It's because you are spanning the entire viewin your rect make you need to subtract the height and width of the tab and nav bartake a look at this example- (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 视图仍然没有加载到正确的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-28 15:53