Disable Screen rotation on specific view.

2 posts, 0 answers
  1. Ray
    Ray avatar
    9 posts
    Member since:
    Mar 2014

    Posted 23 Apr 2014 Link to this post

    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?

  2. Tina Stancheva
    Tina Stancheva avatar
    3298 posts

    Posted 28 Apr 2014 Link to this post

    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() {

    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.

    Tina Stancheva

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

Back to Top