怎么查看網(wǎng)站誰做的北京網(wǎng)絡(luò)推廣有哪些公司
三、組合手勢
由多種單一手勢組合而成,通過在GestureGroup中使用不同的GestureMode來聲明該組合手勢的類型,支持順序識別、并行識別和互斥識別三種類型。
GestureGroup(mode:GestureMode, gesture:GestureType[])
//- mode:為GestureMode枚舉類。用于聲明該組合手勢的類型。//- gesture:由多個手勢組合而成的數(shù)組。用于聲明組合成該組合手勢的各個手勢。
- 順序識別 順序識別組合手勢對應(yīng)的GestureMode為Sequence
//- 手勢將按照手勢的注冊順序識別手勢,直到所有的手勢識別成功。
//- 當(dāng)順序識別組合手勢中有一個手勢識別失敗時,后續(xù)手勢識別均失敗。
//- 順序識別手勢組僅有最后一個手勢可以響應(yīng)onActionEnd。// 這里拖拽事件是一種典型的順序識別組合手勢事件,由長按手勢事件和滑動手勢事件組合而成
@Entry
@Component
struct Index {@State offsetX: number = 0;@State offsetY: number = 0;@State count: number = 0;@State positionX: number = 0;@State positionY: number = 0;@State borderStyles: BorderStyle = BorderStyle.Solidbuild() {Column() {Text('sequence gesture\n' + 'LongPress onAction:' + this.count + '\nPanGesture offset:\nX: ' + this.offsetX + '\n' + 'Y: ' + this.offsetY).fontSize(28)}.margin(10).borderWidth(1)// 綁定translate屬性可以實現(xiàn)組件的位置移動.translate({ x: this.offsetX, y: this.offsetY, z: 0 }).height(250).width(300)//以下組合手勢為順序識別,當(dāng)長按手勢事件未正常觸發(fā)時不會觸發(fā)拖動手勢事件.gesture(// 聲明該組合手勢的類型為Sequence類型GestureGroup(GestureMode.Sequence,// 該組合手勢第一個觸發(fā)的手勢為長按手勢,且長按手勢可多次響應(yīng)LongPressGesture({ repeat: true })// 當(dāng)長按手勢識別成功,增加Text組件上顯示的count次數(shù).onAction((event: GestureEvent|undefined) => {if(event){if (event.repeat) {this.count++;}}console.info('LongPress onAction');}).onActionEnd(() => {console.info('LongPress end');}),// 當(dāng)長按之后進(jìn)行拖動,PanGesture手勢被觸發(fā)PanGesture().onActionStart(() => {this.borderStyles = BorderStyle.Dashed;console.info('pan start');})// 當(dāng)該手勢被觸發(fā)時,根據(jù)回調(diào)獲得拖動的距離,修改該組件的位移距離從而實現(xiàn)組件的移動.onActionUpdate((event: GestureEvent|undefined) => {if(event){this.offsetX = (this.positionX + event.offsetX);this.offsetY = this.positionY + event.offsetY;}console.info('pan update');}).onActionEnd(() => {this.positionX = this.offsetX;this.positionY = this.offsetY;this.borderStyles = BorderStyle.Solid;})).onCancel(() => {console.log("sequence gesture canceled")}))}
}
- 并行識別 并行識別組合手勢對應(yīng)的GestureMode為Parallel
//- 并行識別組合手勢中注冊的手勢將同時進(jìn)行識別,直到所有手勢識別結(jié)束。
//- 并行識別手勢組合中的手勢進(jìn)行識別時互不影響。// 在一個Column組件上綁定點擊手勢和雙擊手勢組成的并行識別手勢
@Entry
@Component
struct Index {@State count1: number = 0;@State count2: number = 0;build() {Column() {Text('Parallel gesture\n' + 'tapGesture count is 1:' + this.count1 + '\ntapGesture count is 2:' + this.count2 + '\n').fontSize(28)}.height(200).width('100%')// 以下組合手勢為并行并別,單擊手勢識別成功后,若在規(guī)定時間內(nèi)再次點擊,雙擊手勢也會識別成功.gesture(GestureGroup(GestureMode.Parallel,TapGesture({ count: 1 }).onAction(() => {this.count1++;}),TapGesture({ count: 2 }).onAction(() => {this.count2++;})))}
}
- 互斥識別 互斥識別組合手勢對應(yīng)的GestureMode為Exclusive
//- 互斥識別組合手勢中注冊的手勢將同時進(jìn)行識別,若有一個手勢識別成功,則結(jié)束手勢識別,其他所有手勢識別失敗。// 在一個Column組件上綁定單擊手勢和雙擊手勢組合而成的互斥識別組合手勢
@Entry
@Component
struct Index {@State count1: number = 0;@State count2: number = 0;build() {Column() {Text('Exclusive gesture\n' + 'tapGesture count is 1:' + this.count1 + '\ntapGesture count is 2:' + this.count2 + '\n').fontSize(28)}.height(200).width('100%')//以下組合手勢為互斥并別,單擊手勢識別成功后,雙擊手勢會識別失敗.gesture(GestureGroup(GestureMode.Exclusive,TapGesture({ count: 1 }).onAction(() => {this.count1++;}),TapGesture({ count: 2 }).onAction(() => {this.count2++;})))}
}