屏幕怎么个不让他翻转, 屏蔽代码是什么哪位哥哥姐姐大哥大嫂叔叔阿姨给我提供一下谢谢
- 发布:2016-02-17 18:19
- 更新:2016-02-18 10:17
- 阅读:8043
如何禁止屏幕翻转
Android 版需要修改 AndroidManifest.xml 文件,在文件中找到 android:screenOrientation 属性,原值应该是 user,修改成 portrait 就是锁定为竖屏。我在文件中共找到两处,不知是否都有用,不管三七二十一索性都改掉了。
这样设置完成后,使用过程中不管手机怎么摆,屏幕都不会自动旋转了。如果某个功能需要横屏,可以用程序设定 plus.screen.lockOrientation("landscape-primary"),但是注意,恢复竖屏要使用 plus.screen.lockOrientation("portrait-primary"),而千万不要使用 plus.screen.unlockOrientation(),因为后者会导致屏幕又可以自由旋转了。
关于 android:screenOrientation 的说明,可以参考下面的网页:
http://developer.android.com/guide/topics/manifest/activity-element.html#screen
http://www.cnblogs.com/snowberg/archive/2012/07/15/2618908.html
iOS 版需要修改 xxx-Info.plist 文件,找到下面的内容:
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
共有 4 个方向,把你不希望出现的屏幕方向删除掉即可。比如只想保留竖屏,就只保留 UIInterfaceOrientationPortrait 这项。
如果要在 XCode 里面修改的话,在项目参数视图的 General 里面找到 Device Orientation,也是 4 个选项。
爱吃鱼的靖哥哥
plus.screen.unlockOrientation()就是个坑
2019-08-29 11:40