How to set orientation in nativescript

偶尔善良 提交于 2019-12-03 05:46:32

My app is portrait orientation only.

For android, you just need to add android:screenOrientation="portrait" in AndroidManifest.xml inside the activity tags.

For iOS, open Xcode -> Select project on project navigator (left panel) -> Select target in middle panel -> Choose "General" tab -> Tick only "Portrait" in Deployment info section

For iOS: (Without Xcode, just manipulate one file.)

  1. Open file app/App_Resources/iOS/Info.plist
  2. Comment out or delete:

    <string>UIInterfaceOrientationLandscapeLeft</string> <string>UIInterfaceOrientationLandscapeRight</string>

app/App_Resources/iOS/Info.plist

    ...     
    <key>UISupportedInterfaceOrientations</key>
    <array>
        <string>UIInterfaceOrientationPortrait</string>
        <string>UIInterfaceOrientationLandscapeLeft</string>
        <string>UIInterfaceOrientationLandscapeRight</string>
    </array>
    <key>UISupportedInterfaceOrientations~ipad</key>
    <array>
        <string>UIInterfaceOrientationPortrait</string>
        <string>UIInterfaceOrientationPortraitUpsideDown</string>
        <string>UIInterfaceOrientationLandscapeLeft</string>
        <string>UIInterfaceOrientationLandscapeRight</string>
    </array>

(Props to @mudlabs, who already mentioned this solution in a comment.)

In case you are using NativeScript Sidekick it is possible to set orientation for Android an iOS from project properties.

The top answer is correct but for some cases, adding only android:screenOrientation does not work.

I got it working by adding android:screenOrientation="portrait" android:configChanges="keyboardHidden|orientation|screenSize" and take note the order, screenOrientation first before the configChanges.

Actually i've tested it in both android studio and the Nativescript.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!