世博相机变焦

时间:2020-06-14 05:13:58

标签: javascript android ios react-native expo

那是我第一次在React Native中使用Pinch Gesture Handler ...我正在尝试使用Expo创建可缩放的相机。我在做什么:

const handlePinch = (nativeEvent) => {
   const { scale, velocity } = nativeEvent;

   let newZoom =
     velocity > 0
       ? zoom + scale * velocity * (Platform.OS === "ios" ? 0.01 : 25)
       : zoom -
         scale * Math.abs(velocity) * (Platform.OS === "ios" ? 0.02 : 50);

   if (newZoom < 0) newZoom = 0;
   else if (newZoom > 0.5) newZoom = 0.5;

   setZoom(newZoom);
};

...

<ExpoCamera
    ...
    zoom={zoom}
    ...
  >

工作但不太顺畅...有什么更好的方法吗?

0 个答案:

没有答案