获取React Native ScrollView的缩放比例或缩放后的尺寸

7

有没有一种方法可以引用缩放的ScrollView的当前尺寸或比例?文档提到了zoomScale,但返回未定义。

我目前尝试过以下方式:

onScrollUpdate() {
    console.log(this.refs.pageScrollView.zoomScale); // returns undefined
    RCTUIManager.measure(findNodeHandle(this.refs.pageScrollView), (x, y, width, height, pageX, pageY) => {
    console.log(width); // returns initial size, but not scaled - this number change when zooming
  });
 }
<ScrollView
    ref='pageScrollView'
    onScroll={this.onScrollUpdate.bind(this)}
    minimumZoomScale={0.95}
    maximumZoomScale={2}
    showsHorizontalScrollIndicator={false}
    showsVerticalScrollIndicator={false}
    scrollEventThrottle={2}
  >
1个回答

0

解决方案已移动@EmmaWilliams的问题帖子中。

The onScroll event receives a nativeEvent which includes zoomScale amount:

onScrollUpdate(event) {
    console.log(event.nativeEvent.zoomScale)  // returns accurate zoomscale
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接