重庆餐饮网站设计,深圳十大外贸公司排名,如何自己做自己的网站,厦门网站建设多少钱五、旋转手势#xff08;RotationGesture#xff09;
RotationGesture(value?:{fingers?:number; angle?:number})
旋转手势用于触发旋转手势事件#xff0c;触发旋转手势的最少手指数量为2指#xff0c;最大为5指#xff0c;最小改变度数为1度#xff0c;拥有两个可…五、旋转手势RotationGesture
RotationGesture(value?:{fingers?:number; angle?:number})
旋转手势用于触发旋转手势事件触发旋转手势的最少手指数量为2指最大为5指最小改变度数为1度拥有两个可选参数
fingers非必选参数用于声明触发旋转手势所需要的最少手指数量最小值为2最大值为5默认值为2。
angle非必选参数用于声明触发旋转手势的最小改变度数单位为deg默认值为1。
以在Text组件上绑定旋转手势实现组件的旋转为例可以通过在旋转手势的回调函数中获取旋转角度从而实现组件的旋转
// xxx.ets
Entry
Component
struct Index {State angle: number 0;State rotateValue: number 0;build() {Column() {Text(RotationGesture angle: this.angle).fontSize(28)// 在组件上绑定旋转布局可以通过修改旋转角度来实现组件的旋转.rotate({ angle: this.angle }).gesture(RotationGesture().onActionStart((event: GestureEvent) {console.info(RotationGesture is onActionStart);})// 当旋转手势生效时通过旋转手势的回调函数获取旋转角度从而修改组件的旋转角度.onActionUpdate((event: GestureEvent) {this.angle this.rotateValue event.angle;console.info(RotationGesture is onActionEnd);})// 当旋转结束抬手时固定组件在旋转结束时的角度.onActionEnd(() {this.rotateValue this.angle;console.info(RotationGesture is onActionEnd);}).onActionCancel(() {console.info(RotationGesture is onActionCancel);}))}.height(200).width(250)}
} 六、滑动手势SwipeGesture
SwipeGesture(value?:{fingers?:number; direction?:SwipeDirection; speed?:number})
滑动手势用于触发滑动事件当滑动速度大于100vp/s时可以识别成功拥有三个可选参数
fingers非必选参数用于声明触发滑动手势所需要的最少手指数量最小值为1最大值为10默认值为1。
direction非必选参数用于声明触发滑动手势的方向此枚举值支持逻辑与和逻辑或|运算。默认值为SwipeDirection.All。
speed非必选参数用于声明触发滑动的最小滑动识别速度单位为vp/s默认值为100。
以在Column组件上绑定滑动手势实现组件的旋转为例
// xxx.ets
Entry
Component
struct Index {State rotateAngle: number 0;State speed: number 1;build() {Column() {Column() {Text(SwipeGesture speed\n this.speed)Text(SwipeGesture angle\n this.rotateAngle)}.border({ width: 3 }).width(300).height(200).margin(100)// 在Column组件上绑定旋转通过滑动手势的滑动速度和角度修改旋转的角度.rotate({ angle: this.rotateAngle }).gesture(// 绑定滑动手势且限制仅在竖直方向滑动时触发SwipeGesture({ direction: SwipeDirection.Vertical })// 当滑动手势触发时获取滑动的速度和角度实现对组件的布局参数的修改.onAction((event: GestureEvent) {this.speed event.speed;this.rotateAngle event.angle;}))}}
} 说明当SwipeGesture和PanGesture同时绑定时若二者是以默认方式或者互斥方式进行绑定时会发生竞争。SwipeGesture的触发条件为滑动速度达到100vp/sPanGesture的触发条件为滑动距离达到5vp先达到触发条件的手势触发。可以通过修改SwipeGesture和PanGesture的参数以达到不同的效果。