views:

829

answers:

1

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.

+2  A: 

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.

Eric Petroelje
You would probably want this to return interfaceOrientation == UIInterfaceOrientationPortrait
Andy Bourassa