Can I lock a UIWebView's orientation with Javascript or HTML?
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 onorientationchange
property of the body
tag.
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:
function touchMove(event) {
// Prevent scrolling on this element
event.preventDefault();
...
}
It doesn't mention anything about preventing orientation changes:
iPhone OS Note: The preventDefault method applies to multi-touch and gesture input in iPhone OS 2.0 and later.
[emphasis added]
Additionally, the orientation property is readonly.
And so, you must write your own code like the one I linked to above.
精彩评论