跳到主要内容

egret.DeviceOrientation

包    egret

类    public class DeviceOrientation

继承    egret.DeviceOrientation → egret.EventDispatcher → egret.HashObject

Orientation 监听设备方向的变化,当方向变化时派发 CHANGE 事件

公共属性​

属性

公共方法​

方法
DeviceOrientation()
start(): void
开始监听设备方向变化
stop(): void
停止监听设备方向变化

事件​

Events

| egret.Event.CHANGE
设备方向改变时派发 |

属性详细信息​

方法详细信息​

DeviceOrientation()​

public DeviceOrientation()

  • 支持版本:all
  • 运行平台:Web,Native

start()​

public start(): void

开始监听设备方向变化

  • 支持版本:Egret 2.4
  • 运行平台:Web

stop()​

public stop(): void

停止监听设备方向变化

  • 支持版本:Egret 2.4
  • 运行平台:Web

示例​

class  DeviceOrientationExample  extends  egret.DisplayObjectContainer  {
label: egret.TextField;
constructor() {
super();
this.label = new egret.TextField();
this.label.y = 50;
this.label.x = 50;
this.addChild(this.label);
var orientation = new egret.DeviceOrientation();
orientation.addEventListener(egret.Event.CHANGE,this.onOrientation,this);
orientation.start();
}
onOrientation(e:egret.OrientationEvent){
this.label.text =
"方向: \nalpha:"+e.alpha
+",\nbeta:"+e.beta
+",\ngamma:"+e.gamma;
}
}