简体   繁体   English

为什么我无法按下 iOS 上的按钮?

[英]Why am I not able to press the button on iOS?

I have a button that I need displayed on top of another element in React Native.我有一个按钮,需要显示在 React Native 中的另一个元素之上。 I have given the button a position of "absolute" and a flex: 1, and it works and looks beautiful on android, but on iOS, it doesn't let the user click the button.我给按钮一个“绝对”的 position 和一个 flex:1,它在 android 上工作并且看起来很漂亮,但是在 iOS 上,它不会让用户点击。 Is there something I am missing?有什么我想念的吗?

The element that the button needs to be on top of is a video player, which the user also needs to be able to click to pause/play.按钮需要位于顶部的元素是视频播放器,用户还需要能够单击以暂停/播放。

Here are the elements:以下是元素:

 <VideoPlayer
          shouldPlay={true}
          useNativeControls={true}
          resizeMode={"contain"}
          source={{
            uri:
              "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4",
          }}
          style={styles.video}
        />
        <View style={styles.exitButton}>
          <ExitButton onPress={backNavigation} />
        </View>

Here are the styles:以下是 styles:

  exitButton: {
    position: "absolute",
    alignItems: "flex-end",
    justifyContent: "flex-end",
    flex: 1,
    width: "100%",
    paddingBottom: 250
  },
  video: {
    height: "100%",
    width: "100%",
    flex: 2
  },

Try adding zIndex in style like below尝试以如下样式添加 zIndex

exitButton: {
    position: "absolute",
    alignItems: "flex-end",
    justifyContent: "flex-end",
    flex: 1,
    width: "100%",
    paddingBottom: 250,
    zIndex: 1
  }

zIndex will help you to add your button on top of the current layer. zIndex将帮助您将按钮添加到当前图层的顶部。 You can give any positive number in index.您可以在索引中给出任何正数。

Also, add some height as well.此外,还要增加一些height As if you have a smaller image, then its very small touchable area.好像您有一个较小的图像,那么它的可触摸区域非常小。

You can get more info on this document .您可以获得有关此文档的更多信息。

exitButton: {
    position: "absolute",
    alignItems: "flex-end",
    justifyContent: "flex-end",
    height: 50,
    width: "100%",
    paddingBottom: 250
  },

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

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