直接上代码
const ref = useRef<View | null>(null);
<View
ref={ref}
style={[t.pB8]}
onLayout={(event) => {
if (ref) {
ref?.current?.measure((x, y, width, height, pageX, pageY) => {
console.log(x, y, width, height, pageX, pageY);
});
}
}}
>
控制台打印结果
![](https://img.haomeiwen.com/i9126595/fe6b56455afb5157.png)
其中onLayout只能拿到x、y、width、height,拿不到PageY,而pageY才是相对于屏幕的坐标
网友评论