簡體   English   中英

反應本地無法捕獲觸摸事件的坐標

[英]react-native unable to capture coordinates of touch event

我正在嘗試捕獲觸摸事件的x,y坐標。 我希望給定屏幕上的任何觸摸事件,我都可以捕獲觸摸的x,y坐標。

我正在使用TouchableOpacity,並且可以響應onPress,但是無法傳遞坐標。

當可觸摸對象觸發onPress處理程序時, onPress事件變量傳遞到處理程序中。 您可以按照以下步驟從事件中提取坐標:

<TouchableOpacity 
    onPress={(event) => {
        const {
            // Location (x,y) is relative to
            // the top-left of the component
            locationX,
            locationY,

            // Page (x,y) is relative to
            // the top-left of the device screen
            pageX,
            pageY,
        } = event.nativeEvent
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM