简体   繁体   English

如何使用 React Native 将图像拆分为小部分并在单击时显示它们?

[英]How to split image into small parts and display them on click with React Native?

This is what I'm aiming to achieve I'm making a small quiz game in React Native where you guess the image by clicking on different parts of it.这就是我想要实现的目标。我在 React Native 中制作了一个小测验游戏,您可以通过单击图像的不同部分来猜测图像。 Initially the image is behind multiple small "blocks" and by clicking on them they disappear.最初,图像位于多个小“块”后面,点击它们就会消失。 How can achieve this functionality in the most elegant way?如何以最优雅的方式实现此功能? I was thinking of making multiple small Views each with the same size and onclick they would disappear.我正在考虑制作多个大小相同的小视图,并且 onclick 它们会消失。 Is this a good approach?这是一个好方法吗? Here's the image of what I'm aiming to achieve: Guess image app这是我想要实现的图像: Guess image app

In my opinion, your approach is the only one.在我看来,你的方法是唯一的。 If you try to split your image, there will be somethings you have to deal with:如果您尝试拆分图像,您将需要处理一些事情:

  1. You might have to use some tools to split your image into smaller one.您可能需要使用一些工具将图像分割成更小的图像。 Because the tool's functionalities, the number of your images, the size of image and the way you include and manage your images in your app, this is really unnecessary, unless you want to show off your skills.因为该工具的功能、图像的数量、图像的大小以及在应用程序中包含和管理图像的方式,这真的是不必要的,除非你想炫耀你的技能。
  2. With 1 image, if you want to make that level harder, eg: create more blocks to hide it, you have to split that image again.对于 1 张图像,如果您想让该级别更难,例如:创建更多块来隐藏它,您必须再次拆分该图像。 Even if you have libraries to do that, your performance will be affected seriously.即使您有库可以这样做,您的性能也会受到严重影响。

And these are some props when you use blocks :这些是您使用blocks时的一些道具:

  1. No need to split image (of course), so say good bye to libraries that decrease your perfomance.不需要分割图像(当然),所以告别降低性能的库。
  2. You can do many things with those blocks , eg: increasing the difficult by adding more blocks, creating block's animation like rolling or phasing, etc.你可以用这些blocks做很多事情,例如:通过添加更多积木来增加难度,创建积木的 animation 像滚动或相位等。
  3. If you don't want to set absolute position to your <Image/> component, RN has built in <ImageBackground/> component to meet up your requirements.如果您不想将绝对 position 设置为您的<Image/>组件,RN 已经内置了<ImageBackground/>组件来满足您的要求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM