user73481
user73481

Reputation: 901

Lock orientation UIWebView on iPhone

Is there a way to lock the orientation of a UIWebView? With Obj-C, JS, or Html? I don't want to have a button or anything I just want it to be locked to portrait as soon as the app opens up.

Upvotes: 2

Views: 3285

Answers (1)

Eric Petroelje
Eric Petroelje

Reputation: 60549

Looks like this stack overflow post may indirectly answer your question. When the iPhone is rotated, the "top level" view is sent the notification, and that view is responsible for laying out its subviews.

If your UIWebView is the top level view, it will autorotate itself. However, if you put the UIWebView inside of another view, and have the view controller for that "container" view implement the shouldAutorateToInterfaceOrientation method like this:

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

That would probably prevent the UIWebView from knowing the interface was rotated. Note that I haven't actually tried this, but it should would work.

Upvotes: 3

Related Questions