W3Cschool
恭喜您成為首批注冊(cè)用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
PanResponder
將幾個(gè)觸發(fā)調(diào)節(jié)成一個(gè)單一的觸發(fā)動(dòng)作。該方法可以使單一觸發(fā)動(dòng)作對(duì)額外的觸發(fā)具有彈性,可以用來(lái)識(shí)別簡(jiǎn)單的多點(diǎn)觸發(fā)動(dòng)作。
它為響應(yīng)處理程序提供了一個(gè)可預(yù)測(cè)包,這個(gè)相應(yīng)處理程序是由動(dòng)作應(yīng)答系統(tǒng)提供的。對(duì)每一個(gè)處理程序,在正常事件旁提供了一個(gè)新的 gestureState
對(duì)象。 一個(gè) gestureState
對(duì)象有以下屬性:
stateID
-gestureState 的ID-在屏幕上保持至少一個(gè)觸發(fā)動(dòng)作的時(shí)間
moveX
-最近動(dòng)態(tài)觸發(fā)的最新的屏幕坐標(biāo)
x0
-應(yīng)答器橫向的屏幕坐標(biāo)
y0
-應(yīng)答器縱向的屏幕坐標(biāo)
dx
-觸發(fā)開始后累積的橫向動(dòng)作距離
dy
-觸發(fā)開始后累積的縱向動(dòng)作距離
vx
-當(dāng)前手勢(shì)的橫向速度
vy
-當(dāng)前手勢(shì)的縱向速度
numberActiveTouch
-屏幕上當(dāng)前觸發(fā)的數(shù)量
componentWillMount: function() {
this._panGesture = PanResponder.create({ // Ask to be the responder: onStartShouldSetPanResponder: (evt, gestureState) => true, onStartShouldSetPanResponderCapture: (evt, gestureState) => true, onMoveShouldSetPanResponder: (evt, gestureState) => true, onMoveShouldSetPanResponderCapture: (evt, gestureState) => true, onPanResponderGrant: (evt, gestureState) => { // The guesture has started. Show visual feedback so the user knows // what is happening! // gestureState.{x,y}0 will be set to zero now
}, onPanResponderMove: (evt, gestureState) => { // The most recent move distance is gestureState.move{X,Y} // The accumulated gesture distance since becoming responder is
// gestureState.d{x,y}
}, onResponderTerminationRequest: (evt, gestureState) => true, onPanResponderRelease: (evt, gestureState) => { // The user has released all touches while this view is the // responder. This typically means a gesture has succeeded
}, onPanResponderTerminate: (evt, gestureState) => { // Another component has become the responder, so this gesture // should be cancelled
},
});
}, render: function() { return (
<View {...this._panResponder.panHandlers} />
);
},
想要查看它的實(shí)際應(yīng)用,嘗試 PanResponder example in UIExplorer。
static create(config: object)
@param {object} 所有應(yīng)答器回調(diào)配置的增強(qiáng)版本,應(yīng)答器回調(diào)不僅可以提供典型的 ResponderSyntheticEvent
,還可以提供 PanResponder
動(dòng)作狀態(tài)。在每一個(gè)典型的 onResponder*
回調(diào)中,用 PanResponder
對(duì) Responder
做簡(jiǎn)單的替換。例如, config
對(duì)象可能看起來(lái)像如下形式:
onMoveShouldSetPanResponder: (e, gestureState) => {...}
onMoveShouldSetPanResponderCapture: (e, gestureState) => {...}
onStartShouldSetPanResponder: (e, gestureState) => {...}
onStartShouldSetPanResponderCapture: (e, gestureState) => {...}
onPanResponderReject: (e, gestureState) => {...}
onPanResponderGrant: (e, gestureState) => {...}
onPanResponderStart: (e, gestureState) => {...}
onPanResponderEnd: (e, gestureState) => {...}
onPanResponderRelease: (e, gestureState) => {...}
onPanResponderMove: (e, gestureState) => {...}
onPanResponderTerminate: (e, gestureState) => {...}
onPanResponderTerminationRequest: (e, gestureState) => {...}
一般來(lái)說(shuō),對(duì)于那些捕獲的等價(jià)事件,我們?cè)诓东@階段更新一次 gestureState ,并且也可以在冒泡階段使用。
在 onStartShould* 回調(diào)時(shí)需要注意一點(diǎn)。在對(duì)節(jié)點(diǎn)的捕獲/冒泡階段的開始/結(jié)束事件中,它們只對(duì)更新后的gestureState
做出反應(yīng)。一旦節(jié)點(diǎn)成為應(yīng)答器,你可以依靠每一個(gè)被動(dòng)作和 gestureState
處理后相應(yīng)更新的開始/結(jié)束事件。 (numberActiveTouches) 可能不完全準(zhǔn)確,除非你是應(yīng)答器。
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: