This is a migrated thread and some comments may be shown as answers.

Disable Screen rotation on specific view.

1 Answer 599 Views
AppBuilder extension for Visual Studio
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Ray
Top achievements
Rank 1
Ray asked on 23 Apr 2014, 09:21 PM
My company is developing a mobile hybrid app and there's a specific view that will look bad if the user decides to rotate their screen.  I know that you can disable landscape mode for your entire application.  Is there a way to disable landscape for a specific view?

Thanks.

1 Answer, 1 is accepted

Sort by
0
Tina Stancheva
Telerik team
answered on 28 Apr 2014, 02:59 PM
Hi Roy,

As this scenario is not very common, there isn't a straight-forward approach that can work for the different platforms. However, there are certain implementations developed for each platform.

For instance, starting in PhoneGap 0.9.5 there's an undocumented iOS only feature that allows you to handle whether the device should rotate to a particular orientation. It exposes the iOS Objective-C method shouldAutorotateToInterfaceOrientation with a JavaScript function shouldRotateToOrientation. Please take a look at the iOS: shouldAutorotateToInterfaceOrientation / Lock Orientation in PhoneGap post for more information on how to take advantage of that method to prevent the rotation of a page.

In Android, on the other hand, I found a custom plugin - OrientationLock, which supports Cordova 3.0+ and is Plugman-compatible. You can follow the steps described in the Import Custom Plugins tutorial to import the plugin in an AppBuilder project. However, please note that while I tested this plugin locally, I was able to lock the screen orientation to "portrait"-only but I was not able to unlock it back. This is why I had to slightly change the implementation of the plugin. In the OrientationLock.java file, I modified the Activity Orientation to be reset to SCREEN_ORIENTATION_SENSOR instead of SCREEN_ORIENTATION_UNSPECIFIED:
public void unlock() {
        this.cordova.getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
    }

Please note that I haven't tested these approaches extensively, which means that you might have to further research the topic and implement an approach that best meets your needs. Also, as both solution work with the orientation of the app, rather than a specific view, I would recommend using them in events indicating that you have navigated to or away from a specific view.

I hope the provided information can get you started.

Regards,
Tina Stancheva
Telerik
 

Share what you think about AppBuilder and Telerik Platform with us in our feedback portal, so we can become even better!

 
Tags
AppBuilder extension for Visual Studio
Asked by
Ray
Top achievements
Rank 1
Answers by
Tina Stancheva
Telerik team
Share this question
or