Can I block the orientation of a UIWebView using Javascript or HTML?

I am working on some HTML content as part of an iPad application. We may need to block the contents of the UIWebView in portrait mode, but the application has already been sent to Apple, and the only link I found to achieve this is in this question , which gives this example

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

But is there a way to achieve the same result from the contents of UIWebViews using HTML or Javascript?

+4
source share
1 answer

You can be notified when the orientation changes using the onorientationchange property of the onorientationchange tag.

You can use code similar to this answer that tracks orientation changes and then flips the content so that it displays to the user in one direction as always.

Note that although you can prevent the default behavior on some events using the following code:

 function touchMove(event) { // Prevent scrolling on this element event.preventDefault(); ... } 

It says nothing about preventing orientation changes:

iPhone OS Note. The preventDefault method is used to enter multi-touch and gestures in iPhone OS 2.0 and later.
[highlighted by me]

In addition, the orientation property is read-only.

So you have to write your own code, like the one I linked to above.

+1
source

Source: https://habr.com/ru/post/1309763/


All Articles