使用TouchableOpacity组件

实现单击事件只需要声明onPress属性即可,其他同理,实现onPressIn,onPressOut,onLongPress

constructor(props){
super(props);
this.state = {
title:'不透明触摸'
}
this.activiEvent = this.activiEvent.bind(this);
}
render() {
return ( <View>
{/*
onPress={this.renderPress()}
onPress={()=>this.activiEvent('点击')}
onPressIn={()=>this.activiEvent('按下')}
onPressOut={()=>this.activiEvent('抬起')}
onLongPress={()=>this.activiEvent('长按')}
*/}
<View>
<TouchableOpacity activeOpacity={0.5}
onPress={()=>this.activiEvent('点击')}
onPressIn={()=>this.activiEvent('按下')}
onPressOut={()=>this.activiEvent('抬起')}
onLongPress={()=>this.activiEvent('长按')}
>
<View>
<Text>我是文本但可以点击常用事件</Text>
</View>
</TouchableOpacity>
</View> <View>
<Text>{this.state.title}</Text>{/*标签内取值要用花括号*/}
</View> </View> );
} renderPress(){
{/*还没点击就弹窗了 花括号注释不能写到函数外 标签内注释用花括号 标签外可以用// */} Alert.alert('iOS')
} activiEvent(event){
this.setState({
title:event
})
}

最新文章

  1. 一位同事对 Rafy 框架的一些建议及我的回复
  2. SharePoint 2016 图文安装教程
  3. angular animate
  4. File Checksum Integrity Verifier
  5. CVE-2015-7547
  6. 让你的linux操作系统更加安全【转】
  7. getaccesstoken方法
  8. iOS 性能优化:Instruments
  9. 最近用的到的一些js的常用方法(简单的)
  10. oracle切割字符串后以单列多行展示
  11. javascript中类的属性访问权限研究(1)
  12. Bootstrap中的strong和em强调标签
  13. 集成CCFlow工作流与GPM的办公系统驰骋CCOA介绍(一)
  14. CGroup Namspace
  15. Netty 服务端启动过程
  16. YARN集群的mapreduce测试(五)
  17. k8s资料转载
  18. 85. Maximal Rectangle (Graph; Stack, DP)
  19. MIT-6.828-JOS-lab1:C, Assembly, Tools, and Bootstrapping
  20. javascript ES6模块化

热门文章

  1. 【ABAP系列】SAP ABAP 刷新SCREEN的方法
  2. java中线程同步的理解(非常通俗易懂)
  3. Struts学习(一)
  4. Two modules in a project cannot share the same content root报错解决方案
  5. 使用CyclicBarrier+线程池,按总页数分批次开多线程执行逻辑
  6. java基础语法详细介绍
  7. Linux——临界段,信号量,互斥锁,自旋锁,原子操作
  8. Python入门之 Python内置函数
  9. Let&#39;s encrypt 通配域名DNS验证方式的证书自动更新
  10. CodeForces - 714E + POJ - 3666 (dp严格单调递增与非严格单调递增)