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?
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.
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.
精彩评论