Setting orientation programmatically

Your app can request orientation changes while it's running. Any app can request a rotation even if it is locked to a particular orientation or the device is locked by the user.

If you're using Cascades APIs, you can use the supportedDisplayOrientation property of the OrientationSupport class to set the orientation of your app programmatically as it runs. If you change the supportedDisplayOrientation property programmatically, the supportedDisplayOrientationChanged() signal is emitted.

If the value of the Orientation drop-down list in your bar-descriptor.xml file is anything other than Auto-orient, setting supportedDisplayOrientation to SupportedDisplayOrientation::All results in the app being notified of 180 degree rotations only. Rotations from portrait to landscape orientation, or from landscape to portrait orientation, do not result in app notifications. If your app needs to respond to all device rotations, make sure to set the Orientation value in the bar-descriptor.xml file to Auto-orient. For more information, see Setting orientation in the bar-descriptor.xml file.

If you're using C APIs, to set the orientation of your app programmatically, your app calls navigator_orientation_check_response() with the will_rotate parameter set to true. The navigator service initiates the rotation when the device is in an acceptable state to support it. When the request is successful, the navigator service initiates the rotation sequence using the same steps as in Orientation changes in C.

Set orientation programmatically

Here is an example of how to set your app to portrait orientation after a Page is created:

onCreationCompleted: { 
    OrientationSupport.supportedDisplayOrientation = 
        SupportedDisplayOrientation.DisplayPortrait;  
    }

Coming soon

Not applicable

Last modified: 2015-07-24



Got questions about leaving a comment? Get answers from our Disqus FAQ.

comments powered by Disqus