Disable auto-rotate in Jquery Mobile or PhoneGap

前端 未结 4 1951
梦毁少年i
梦毁少年i 2021-02-14 01:02

Although cross platform development for mobile devices is so good. There isn\'t a simple option to disable auto-rotate or lock into one orientation i.e. portrait or landscape.

相关标签:
4条回答
  • 2021-02-14 01:43

    For iOS, edit the PhoneGap.plist file (e.g. in Xcode). Make sure only portrait is set and uncheck autorotate.

    On Android, you need to edit AndroidManifest.xml. Add android:screenOrientation="portrait" in the activity.

    0 讨论(0)
  • 2021-02-14 01:44

    To complete the answer above.

    On iPhone add this to -info.plist:

    <dict>
    `.....
        <array>
            <string>UIInterfaceOrientationPortrait</string>
            <string>UIInterfaceOrientationPortraitUpsideDown</string>
        </array>
    ..........
    </dict>
    

    on Android to AndroidManifest.xml

    <activity   ........      android:screenOrientation="portrait">
    
    0 讨论(0)
  • 2021-02-14 01:46

    Cordova allows you to set this in config.xml

    Just add this line within the <widget></widget> tags:

    <preference name="Orientation" value="portrait" />
    

    You can also use landscape above for the opposite effect.

    Source: Apache Cordova DOcumentation - The config.xml File

    0 讨论(0)
  • 2021-02-14 01:50

    On PhoneGap you can now specify the application wide orientation in the config.xml file (note that you then won't receive any orientationchange event anymore, so this isn't the right solution if you just want to enable/disable the auto rotation on some pages only)

    <preference name="orientation" value="portait" />
    
    0 讨论(0)
提交回复
热议问题