簡體   English   中英

UIWebView框架在加載橫向和縱向時填充屏幕

[英]UIWebView frame to fill screen when loaded landscape and portrait

我在我的視圖中添加了一個UIWebView,當我在肖像時它工作正常。 但是,當我在橫向加載相同的UIWebView時,它不會填滿屏幕。 我懷疑它來自我如何設置框架:

CGRect screen = [[UIScreen mainScreen] bounds];
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, screen.size.width, screen.size.height)];
webView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
webView.scalesPageToFit = YES;

有沒有更好的方法來這樣做,它將在橫向和縱向正確加載,並在旋轉時填充屏幕?

我遇到了同樣的問題..在我記錄了self.view.frame.size.width后,我很驚訝地發現它是320而不是480.解決方法是:

- (void)viewWillAppear:(BOOL)animated {
[self.view setBounds:CGRectMake(0.f, 0, self.view.frame.size.width, self.view.frame.size.height)];
[self.view setCenter:CGPointMake(self.view.frame.size.width/2, self.view.frame.size.height/2)];
[(UIWebView*)myWebView setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];}

似乎在顯示視圖之前返回了正確的self.frame大小:)

你有多確定父視圖調整到全寬? UIWebView子視圖不會比它的父級大...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM