TouchableOpacity onPress在ScrollView中无法使用。

问题描述 投票:1回答:1

(仅限iOS系统)<TouchableOpacity> 如果它在一个叫 "T "的东西里面,就不会有反应。<ScrollView> :

  1. 在模拟器中能正常工作,但在真实设备中却不能。
  2. keyboardShouldPersistTaps="always" 无所谓
  3. 部分代码。<ScrollView style={styles.scrollView}> <TouchableOpacity style={styles.xButton} onPress={() => this._onClose()}>

有什么建议吗?

--- 代码更新 -----

<ScrollView style={styles.scrollView}>
   <TouchableOpacity style={styles.xButton} onPress={() => this._onClose()}>
    <Image style = {styles.xImg} source = {require('../../images/xbtn.png')}/>
   </TouchableOpacity>
     {this._renderPricing()}
     {this._renderServices()}
 </ScrollView>

和造型是这样的。

scrollView:{ 
    width: width,
    height: height,
}, xButton: {
    position: 'absolute',
    zIndex: 1,
    marginTop: '1%',
    marginRight: '3%',
    alignSelf: 'flex-end',

},xImg: {
    resizeMode: 'contain',
    aspectRatio: .6,
    opacity: 0.5,
},
ios react-native scrollview touchableopacity
1个回答
0
投票

这个问题已经解决了。这是因为在我的单独的渲染方法中的 this._renderPricing 等我改变状态的次数太多"■▄▄■▓,因此JS线程被占用,所以TouchableOpacity无法对触摸事件做出响应"""。RN文件 如有需要,可向您索取更详细的解释。非常感谢您的回答。

© www.soinside.com 2019 - 2024. All rights reserved.