ios - TouchableOpacity onPress在ScrollView中不起作用

标签 ios react-native scrollview touchableopacity

(仅限iOS)<TouchableOpacity>如果在<ScrollView>内部,则不响应:

  • 它可以在模拟器中正常运行,但不能在真实设备
  • 中运行
  • keyboardShouldPersistTaps="always"没有任何区别
  • 部分代码:<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,
    },
    

    最佳答案

    问题已解决。这是由于在我的单独渲染方法中this._renderPricing等更改状态的次数过多-因此,JS线程已被占用,因此TouchableOpacity无法响应触摸事件。如果需要,请参见RN documentation进行更详细的说明。非常感谢您的回答。

    关于ios - TouchableOpacity onPress在ScrollView中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46568854/

    相关文章:

    android - 图像数据使用

    ios - AWS iOS S3 异常 : Invalid region string

    react-native - 当我按下按钮时更改 TextInput 可编辑属性

    android - 如何在 ScrollView 内将线性布局强制到屏幕底部?

    android - 如何创建不在 ScrollView 中或 ScrollView 已禁用的 ListView?

    iphone - 如何检查 NSString 是否包含数值?

    ios - 每次单击按钮时将 UIButton 旋转 90 度

    android - systrace:无法创建/sys/kernel/debug/tracing/trace_marker:没有这样的文件或目录

    javascript - 从函数中的子组件调用 prop 不起作用

    android - 当 ScrollView 不在顶部时禁用 SwipeRefreshLayout