新聞中心
PanResponder 將幾個(gè)觸發(fā)調(diào)節(jié)成一個(gè)單一的觸發(fā)動(dòng)作。該方法可以使單一觸發(fā)動(dòng)作對(duì)額外的觸發(fā)具有彈性,可以用來識(shí)別簡單的多點(diǎn)觸發(fā)動(dòng)作。

鐘樓網(wǎng)站建設(shè)公司創(chuàng)新互聯(lián)公司,鐘樓網(wǎng)站設(shè)計(jì)制作,有大型網(wǎng)站制作公司豐富經(jīng)驗(yàn)。已為鐘樓近千家提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\成都外貿(mào)網(wǎng)站建設(shè)公司要多少錢,請找那個(gè)售后服務(wù)好的鐘樓做網(wǎng)站的公司定做!
它為響應(yīng)處理程序提供了一個(gè)可預(yù)測包,這個(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)前手勢的橫向速度 -
vy-當(dāng)前手勢的縱向速度 -
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 (
);
},
工程實(shí)例
想要查看它的實(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 做簡單的替換。例如, config對(duì)象可能看起來像如下形式:
-
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) => {...}
一般來說,對(duì)于那些捕獲的等價(jià)事件,我們在捕獲階段更新一次 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)答器。
當(dāng)前名稱:創(chuàng)新互聯(lián)React教程:全景響應(yīng)器
本文鏈接:http://fisionsoft.com.cn/article/coesgij.html


咨詢
建站咨詢
