2014-11-22 59 views
0

我以爲我已經清理了,但顯然不是。我使用下面的代碼將webview設置爲出現在頂部的標籤欄和底部的標籤欄之間。這發生在我的viewDidLoad()方法中。在我測試過的所有模擬器上都能正常工作,但是當我測試朋友的iPhone 4s運行7.1.1時,webview呈現跨越屏幕的整個高度,同時覆蓋頂部標籤欄和底部標籤欄。IOS查看仍然沒有加載到正確的位置

如何在所有設備和操作系統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; 

回答

1

這是因爲你在你的矩形覆蓋了整個視圖 讓你需要減去的標籤和導航欄

的高度和寬度來看看這個例子

- (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]; 


} 
+0

不幸的是蘋果還沒有解決這個問題。我的意思是我無法想象我想讓我的內容被酒吧或鍵盤覆蓋的場景。 – 2014-11-22 23:33:59

+0

這是一個恥辱,這並不簡單。爲什麼上面的代碼適用於其他設備?在夜晚結束之前,我會測試這段代碼,看看會發生什麼。謝謝 – Voltron 2014-11-22 23:39:02

+0

我不確定爲什麼完全由於某種原因,新的操作系統試圖覆蓋一切,至少可以說是相當令人沮喪。我希望我有一個更簡單的方法,但我肯定還沒有想過。 – 2014-11-22 23:41:24