by_name
by_name
  • 发布:2016-02-17 18:19
  • 更新:2016-02-18 10:17
  • 阅读:8043

如何禁止屏幕翻转

分类:HBuilder

屏幕怎么个不让他翻转, 屏蔽代码是什么哪位哥哥姐姐大哥大嫂叔叔阿姨给我提供一下谢谢

2016-02-17 18:19 负责人:无 分享
已邀请:
maq

maq

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

DCloud_Android_ST

DCloud_Android_ST

hbuilder工程下manifest.json,应用信息,根据重力感应自动横竖屏,选择你希望的样式。

maq

maq

manifest.json 里的设置仅在云打包时有用,离线打包的话需要自己手工修改原生项目配置。我正在摸索……

maq

maq

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 个选项。

maq

maq

说了半天,其实最简单的解决方案恐怕是在 launch webview 启动之后调用 plus.screen.lockOrientation("portrait-primary") 就可以了,一行程序搞定,而且是跨平台的 :)

唯一的问题可能是启动屏(splash)不受控制,仍然是可以自动旋转的。

该问题目前已经被锁定, 无法添加新回复