我在 Intel XDK 中做了一个简单的应用程序。当我测试应用程序时,我注意到他们启用了加速度计。
对于此应用程序,它只需要 1 个位置。如何禁用加速度计?
提前致谢。
它不是引起的加速度计,而是需要固定的设备方向。
调用此 API 以修复方向:触发intel.xdk.device.setRotateOrientation(ORIENTATION);
后。intel.xdk.device.ready
完整的文档在这里
肖像:intel.xdk.device.setRotateOrientation("portrait");
景观:intel.xdk.device.setRotateOrientation("landscape");
两者:intel.xdk.device.setRotateOrientation("any");
下面是示例代码:
<!DOCTYPE html>
<html>
<head>
<title>XDK</title>
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0;" />
<script src="intelxdk.js"></script>
<script>
document.addEventListener("intel.xdk.device.ready", onDeviceReady, false);
function onDeviceReady(){
// set orientation
intel.xdk.device.setRotateOrientation('landscape');
// intel.xdk.device.setRotateOrientation('portrait');
// intel.xdk.device.setRotateOrientation('any');
intel.xdk.device.hideSplashScreen();
}
</script>
<style>
body {font-family:arial;background-color:white}
</style>
</head>
<body>
<h1>Hello World</h1>
<p>Locked to Landscape</p>
</body>
</html>
接下来可以这样做:
您选择,横向或纵向。如果您模拟项目,您会看到更改。
使用setRotateOrientation
- 方法:
要将设备锁定为纵向模式,请使用:
intel.xdk.device.setRotateOrientation("portrait");
适用于 Android 和 iOS。
请参阅:文档
更简单的是转到构建设置 -> 您的平台 -> 方向。那非常快速和简单。