W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
用于觸發(fā)滑動事件,滑動速度大于100vp/s時可識別成功。
從API Version 8開始支持。后續(xù)版本如有新增內(nèi)容,則采用上角標(biāo)單獨標(biāo)記該內(nèi)容的起始版本。
SwipeGesture(value?: { fingers?: number; direction?: SwipeDirection; speed?: number })
參數(shù):
參數(shù)名稱 | 參數(shù)類型 | 必填 | 參數(shù)描述 |
---|---|---|---|
fingers | number | 否 | 觸發(fā)滑動的最少手指數(shù),默認(rèn)為1,最小為1指,最大為10指。 默認(rèn)值:1 |
direction | SwipeDirection | 否 | 觸發(fā)滑動手勢的滑動方向。 默認(rèn)值:SwipeDirection.All |
speed | number | 否 | 識別滑動的最小速度(默認(rèn)為100VP/秒)。 默認(rèn)值:100 |
名稱 | 描述 |
---|---|
All | 所有方向。 |
Horizontal | 水平方向,手指滑動方向與x軸夾角小于45度時觸發(fā)。 |
Vertical | 豎直方向,手指滑動方向與y軸夾角小于45度時觸發(fā)。 |
None | 任何方向均不可觸發(fā)。 |
- // xxx.ets
- @Entry
- @Component
- struct SwipeGestureExample {
- @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)
- .rotate({ angle: this.rotateAngle })
- // 單指豎直方向滑動時觸發(fā)該事件
- .gesture(
- SwipeGesture({ direction: SwipeDirection.Vertical })
- .onAction((event: GestureEvent) => {
- this.speed = event.speed
- this.rotateAngle = event.angle
- })
- )
- }.width('100%')
- }
- }
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: