Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIView autoresizingmask not working for me

I have my app set up so that auto-rotate works. Things like tableviewcontrollers and tabbarcontrollers automatically resize them selves without the need for me to write any code. However I need my webview etc. to resize when the device is turned to landscape. I set:

    webView.autoresizingMask = UIViewAutoresizingFlexibleWidth;

but when I rotate the device it does not resize. I am implementing this incorrectly?

like image 225
john Avatar asked Jan 01 '10 06:01

john


2 Answers

I think I finally figured this out. It seems that the root view of a NIB file does not allow you to specify flexible width and flexible height for the autoresizing mask in interface builder (at least not as of 3.2). Take a look. Putting the following code in your viewDidLoad seems to fix the problem:

self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

I did it after the super call.

like image 200
John Bushnell Avatar answered Nov 26 '22 14:11

John Bushnell


I implement the following in my view controller:

- (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    [self.webView setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
}

Seems to work well.

like image 20
Alex Reynolds Avatar answered Nov 26 '22 16:11

Alex Reynolds