Thizzer
Thizzer

Reputation: 16653

UIWebView rotate content

When autorotating to Landscape mode the size of my UIWebView changes perfectly, only the content remains in Portrait mode.

How do I let the UIWebView display the content in Landscape mode as well?

Edit There is really nothing special about the code;

I connect the UIWebView in the Nib file and in the UIViewController I do;

[webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://google.com"]]];

and

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return YES;
}

The UIWebView changes size correctly, but the content doesn't rotate.

Upvotes: 0

Views: 11756

Answers (4)

Anthony De Souza
Anthony De Souza

Reputation: 554

As of iOS 6 upwards, this no longer applies because shouldAutorotateToInterfaceOrientation has been depreciated see here for a solution

Tozar's solution worked best for me.

In my ViewController's ViewDidLoad I added self.view.autoresizesSubviews = YES;

Upvotes: 2

Jon Conner
Jon Conner

Reputation: 157

Have you tried setting the UIViewController's view to the UIWebView?

[self setView:webView];

Upvotes: 8

Tozar
Tozar

Reputation: 986

Make sure autoresizesSubviews = YES for all of the parent views of your UIWebView.

You should also try simply setting a breakpoint in your shouldAutorotateToInterfaceOrientation: method to make sure it is actually being called. It will give you a better idea of what is going wrong in your code.

Upvotes: 1

Bourne
Bourne

Reputation: 10302

check if the shouldAutorotateToInterfaceOrientation method has been overridden to return a YES, hence supporting all orientations for the UIWebView. And load the webview using a UIViewController

Upvotes: 1

Related Questions