【发布时间】:2021-06-16 05:01:31
【问题描述】:
当我单击某个位置时,我试图在该新闻位置放置一张图片,但我遇到了错误。当我点击一个已经存在的贴纸时,它会获得相对于贴纸的 on press 坐标,所以如果我点击我已经存在的贴纸的左上角,它只会在屏幕的左上角。为什么会这样?这是我的代码
<TouchableOpacity
activeOpacity={1}
onPress={(event: GestureResponderEvent) => {
const { locationX: x, locationY: y } = event.nativeEvent;
setStickers(stickers.concat({ x, y }));
console.log("X: " + x);
console.log("Y: " + y);
}}
style={styles.imageButton}>
<Image style={styles.fullImage} source={{ uri }} />
{stickers.map((sticker, index) => {
return (
<Image
source={stickerImage}
style={{
width: 100,
height: 100,
position: "absolute",
top: sticker.y,
left: sticker.x,
}}
key={index}
/>
);
})}
</TouchableOpacity>
【问题讨论】:
标签: javascript reactjs react-native mobile-development onpress