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;