RN中获取View的位置

2019-05-23  本文已影响0人  偶然中的必然
<View ref="test" style={[styles.item, {}]}></View>
const handle = findNodeHandle(this.refs.test);

UIManager.measureInWindow(handle, (x, y, width, height) => {
     console.log('绝对位置x', x);
     console.log('绝对位置y', y);
     console.log('组件宽度', width);
     console.log('组件高度', height);
 })

UIManager.measure(handle ,(x, y, width, height, X, Y) => {
     console.log('相对父视图位置x', x);
     console.log('相对父视图位置y', y);
     console.log('组件宽度', width);
     console.log('组件高度', height);
     console.log('绝对位置x', X);
     console.log('绝对位置y', Y);
 })
import {
    findNodeHandle,
    UIManager
} from 'react-native'
上一篇 下一篇

猜你喜欢

热点阅读