Turn on Orientation in UIWebview during Javascript Evaluation

As I begin assessing the javascript, such as when a user selects text and it becomes highlighted, I encounter issues with the device orientation on my iPad. The orientation stops working until the javascript finishes executing.

Is there a way to manage javascript evaluation in a uiwebview without impacting the uiwebview orientation?

Answer №1

Indeed. When initializing your JavaScript, you can define a boolean variable and set a variable with the current orientation of your UIViewController (both within your UIViewController instance). After that, you need to implement the following method in your UIViewController:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return YES;
}

This method informs the iPhone whether it can rotate your app when users rotate the device.

Therefore, when your JavaScript begins:

// BOOL stopRotation; // declare it in yourViewController.h stopRotation = TRUE; // UIInterfaceOrientation* currentOrientationFrozen; // declare it in yourViewController.h currentOrientationFrozen = self.interfaceOrientation;

Additionally, add the following code snippet:

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
        if (stopRotation){
             if (interfaceOrientation == currentOrientationFrozen) {
                 return YES;
             } else {
                 return NO;
             }
        } 
        return YES;
    }

Finally, when your JavaScript concludes, reset your BOOL and currentOrientationFrozen variables:

stopRotation = FALSE;
currentOrientationFrozen = nil;

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for specifically targeting the clicked table row using angularJS directives ng-show and ng-hide

Seeking assistance with implementing a toggle function in an angularJS app for showing/hiding a specific table data section. Currently, the toggling functionality is working, but it toggles every row in the table instead of just the clicked row. See this e ...

Issue when attempting to animate an SVG point using translateX transformation

I am attempting to create a basic animation using the translate X property on a section of my svg when hovering over the element. Here is the code I have so far: <html> <style> .big-dot:hover { transform: translateX(20px); animat ...

Parsing JSON data in JavaScript

I am facing an issue with parsing JSON using JavaScript. After the completion of the loop, my variable 'text' is not getting the expected result. Can someone please explain how I can correctly parse this JSON? var xmlr = null; var text = '& ...

Sign up for a Jquery template event

When utilizing a jquery template, the following HTML markup is being used: <div id="results"> <div class="CommentItem" commentid="33064" id="33064" data-guid="/Profile/Profile.aspx?id=Charliedog33"> <div class="CommentPic" ...

What could be causing the readTextFile function to return undefined?

var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest; function readFile(file) { let fileContents = new XMLHttpRequest(); fileContents.open("GET", file, false); fileContents.onreadystatechange = function () { ...

How can I pass a value to a javascript function when a button in asp.net is clicked?

For the client side code, I have written the following: <script> function initialize(x, y) { alert(x); alert(y); var mapProp = { center: new google.maps.LatLng(x, y), zoom: 7, mapTy ...

When I apply the overflow hidden property, the wrapped text magically disappears

Looking for a solution to the text wrapping issue in this content---> trying to figure out what can be done here as I am testing the waters and exploring new territory with my work. Am I getting closer? Or farther away? Testing, testing, ...

Encountering vulnerabilities during the deployment of my React App using NPM has presented a challenge

Just starting out with React Js and seeking some guidance. I've developed a small React app that filters team members based on text input, and it's running smoothly in the development environment when I start NPM. Please review my project and poi ...

Switch between two PHP files with a toggle feature using jQuery click event

Need help with toggling between two PHP files - cab.php and d3.php. Toggling within the same file works fine, but encountering issues when trying to toggle from one file to another. function botaod2mostraesconde() { $(".wrapd2").toggle(); $( ...

Analyzing data from radio button selections using React Hooks calculations

My goal is to calculate the total price based on user inputted values. The total price depends on "ToppingPrice", "Size", and "Qty". Currently, my code is not calculating the total price correctly as I am still learning React. const [quantity, setQuantit ...

Create a generic function that retrieves a specific property from an array of objects using the select method

Currently, I have implemented four functions that select entries from an array based on different properties. if ($scope.filters.filter1) $scope.filteredEntries = $scope.filteredEntries.filter(function (o) { return o.field1 === $scope.filt ...

jquery's animation causing elements to move abruptly when containing text

For the past hour, I've been grappling with jQuery and could really use some assistance. The following example showcases smooth animations: when you click on either of the divs, the selected div will move left or right if the viewport is wider than 70 ...

Using Javascript to parse SOAP responses

Currently, I am working on a Meteor application that requires data consumption from both REST and SOAP APIs. The SOAP service is accessed using the soap package, which functions properly. However, I am facing challenges with the format of the returned data ...

Tips for ensuring an element stays anchored at the bottom even when the keyboard is displayed

I recently encountered a situation on one of my pages where an element positioned at the bottom using absolute positioning was causing issues when the keyboard was opened, as it would move to the middle of the page unexpectedly. While this may seem like a ...

When the oncuechange event is triggered, it initiates a smooth fade-in/fade-out animation within the HTML P tag

Just starting out with web development and learning JavaScript. Trying to create a webpage that displays lyrics synced with an audio file inside a p tag. The subtitles are sourced from a vet file extension and I am using the "cuechange" event in JavaScript ...

Capture the responseBody data within a Newman script from a Postman collection and save it to a

I'm trying to execute a script.js using newman with a locally saved postman collection. The call is successful in postman, returning a token in the response body that I need to access. I would prefer not to open postman every time just to get the res ...

JQuery Datatables: Struggling to make JQuery function work following AJAX update

Watch this screencast to get a clearer understanding of the issue.... I'm currently working on my first project involving AJAX, and I'm encountering some obstacles. The datatable is loading user details from a JSON output using AJAX. Each row ...

React Error: Unable to iterate over this.state.descriptions

Currently facing an issue while trying to resolve this error https://i.stack.imgur.com/BZ304.png The goal is to generate an automated form using the following function: let descriptionsForm = ( <form> {this.state.descriptions.map((d ...

Eslint is not functioning properly on the local machine

Having trouble setting up eslint for my project. When I try to run eslint --init, I keep getting this error: /usr/lib/node_modules/eslint/lib/cli.js:18 let fs = require("fs"), ^^^ SyntaxError: Unexpected strict mode reserved word at exports.runInThis ...

The component 'AppComponent' cannot access the property 'results'

Having some trouble accessing the results field from a json response. The error message reads, Property 'results' does not exist on type 'AppComponent'. import { Component } from '@angular/core'; // Import `HttpClient` impor ...