I’m working on some HTML content as part of an iPad app. We may need to lock the content of the UIWebView to portrait mode, but the app has already been submitted to Apple and the only reference I’ve found to achieveing this is in this question which gives this example
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return NO;
}
But is there any way to achieve the same thing from within the UIWebViews content with HTML or Javascript?
You can be notified when the orientation changes, by using the
onorientationchangeproperty of thebodytag.You can use code similar to this answer’s, which monitors the orientation change and then flips the content so that it appears to the user as always facing one direction.
Note that while you can prevent default behavior on some events using code like this:
It doesn’t mention anything about preventing orientation changes:
Additionally, the orientation property is readonly.
And so, you must write your own code like the one I linked to above.