UIWebView frame to fill the screen when loading landscape and portrait

I am adding a UIWebView to my view, which works great when I am in portrait. But when I load the same UIWebView into the landscape, it does not fill the screen. I suspect this is due to the way I set the frame:

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;

Is there a better way to do this so that it boots correctly in both landscape and portrait orientation and fills the screen when turning?

+3
source share
2 answers

How confident are you that the size of the parent view is resized to full width? The mobility of a UIWebView will not be greater than the parent ...

0
source

. , 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 :)

0

All Articles