React Native學習-measure測量view的寬高值


measure()測量是根據view標簽中的ref屬性,使用方法如下:

measureWatermarkerImage(){
this.refs.watermarkerImage.measure((a, b, width, height, px, py) =>
this.setState({watermarkerImageWidth: width})
);
}

with:寬;height:高;px:x軸方向距離左邊多少像素;py:y軸方向距離上邊多少像素;

根據項目需要,如果需要在頁面加載完成后進行測量view,就需要使用setTimeout():

componentDidMount() {
setTimeout(this.measureWatermarkerImage.bind(this));
};


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM