How to set orientation in nativescript

前端 未结 4 425
面向向阳花
面向向阳花 2020-12-15 07:50

Hello I would like to know how to set device orientation in nativescript. Specifically I want the application that I am writing to stay in the same orientation (portrait) a

相关标签:
4条回答
  • 2020-12-15 08:05

    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.)

    0 讨论(0)
  • 2020-12-15 08:11

    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.

    0 讨论(0)
  • 2020-12-15 08:14

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

    0 讨论(0)
  • 2020-12-15 08:18

    You will have to update your AndroidManifest.xml & Info.plist in your App_Resources.

    AndroidManifest.xml

    Set screenOrientation to portrait on your main activity

    <activity android:name="com.tns.NativeScriptActivity" 
     ... 
     android:screenOrientation="portrait">
    

    Info.plist

    Keep only the portrait orientation, remove rest from UISupportedInterfaceOrientations.

    <key>UISupportedInterfaceOrientations</key>
    <array>
      <string>UIInterfaceOrientationPortrait</string>
    </array>
    <key>UISupportedInterfaceOrientations~ipad</key>
    <array>
      <string>UIInterfaceOrientationPortrait</string>
      <string>UIInterfaceOrientationPortraitUpsideDown</string>
    </array>
    

    Note: Make sure you run a clean build after these changes.

    0 讨论(0)
提交回复
热议问题