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}
  >

编辑:我找到了答案,所以这可能对其他人有所帮助。onScroll 事件接收一个包含 zoomScale 数量的 nativeEvent:

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

0 回答 0