【问题标题】:How to make the three images touchable如何使三个图像可触摸
【发布时间】:2019-08-07 01:02:41
【问题描述】:

请帮我制作可触摸的图像,以便我可以调用 onPress 函数

renderSideButtons = (isGift: boolean) => {
    return (
      <View style={{ bottom: 745 }}>     
        <View style={styles.threeButtonsCustom}>
          {isGift && 
          <TouchableOpacity style={styles.threeButtons}
            onPress={this.openAllergenList}>            
            <Image 
              style={[styles.threeButtons, { top: 545 }]} 
              source={require('../../assets/images/icons/gift_fbutton.png')} 
              />
          </TouchableOpacity>}
          <TouchableOpacity style={styles.threeButtons}>
            <Image
              source={require('../../assets/images/icons/star_white.png')}
              style={[styles.threeButtons, { top: 235 }]}
            />
          </TouchableOpacity>
          <TouchableOpacity style={styles.threeButtons}>
            <Image
              source={require('../../assets/images/icons/share_white.png')}
              style={[styles.threeButtons, { top: 195 }]}
            />
          </TouchableOpacity>
        </View>      
      </View>
    );
  };

这里是styles.threeButtons 样式

threeButtons: {
    position: 'absolute', 
    right: 175, 
    width: 50, 
    resizeMode: 'contain', 
    flexDirection: 'row-reverse'
  },

以及额外的样式

threeButtonsCustom:{ 
flex: 1, 
flexDirection: 'row-reverse', 
position: 'absolute', 
marginTop: '20%', 
zIndex:1 }

[1]:https://imgur.com/a/46K5bvi 例如礼物图片

【问题讨论】:

  • 在threeButtons样式中添加“zIndex:1”
  • 你想一次点击三张图片吗?
  • 我有 zIndex: 1 在上视图 {styles.threeButtonsCustom} 我也应该粘贴抱歉,threeButtonsCustom:{ flex: 1, flexDirection: 'row-reverse', position: 'absolute', marginTop : '20%', zIndex:1 },它没有帮助。
  • 我想单独点击它们,但现在它们甚至无法点击
  • 什么是threeButtons自定义样式,请分享。

标签: android image react-native touchableopacity


【解决方案1】:

我在您的代码中注意到了几件事。

  1. 您正在代码中打开一个条件部分,但似乎没有关闭它。看看{isGift &amp;&amp;,告诉我你在哪里关闭你的大括号。

  2. 您只为最顶层的TouchableOpacity 定义了一个onPress。您目前无法单击任何其他按钮,因为这样做不会发生任何事情。

解决这两个问题,然后告诉我你在哪里。

另外,为了将来参考,您应用到您有疑问的组件的任何样式都可以在您的初始问题中给出,并且在提供人们在 cmets 中要求的样式时,应该对您的问题进行编辑,以便将来访问者可以很容易地看到它。

【讨论】:

  • 谢谢你,我只是重写了整个函数,我使用了 flex,现在它可以工作了
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-02-24
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多