React Native 之TouchableOpacity组件
2024-09-05 20:26:07
使用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
})
}
最新文章
- 一位同事对 Rafy 框架的一些建议及我的回复
- SharePoint 2016 图文安装教程
- angular animate
- File Checksum Integrity Verifier
- CVE-2015-7547
- 让你的linux操作系统更加安全【转】
- getaccesstoken方法
- iOS 性能优化:Instruments
- 最近用的到的一些js的常用方法(简单的)
- oracle切割字符串后以单列多行展示
- javascript中类的属性访问权限研究(1)
- Bootstrap中的strong和em强调标签
- 集成CCFlow工作流与GPM的办公系统驰骋CCOA介绍(一)
- CGroup Namspace
- Netty 服务端启动过程
- YARN集群的mapreduce测试(五)
- k8s资料转载
- 85. Maximal Rectangle (Graph; Stack, DP)
- MIT-6.828-JOS-lab1:C, Assembly, Tools, and Bootstrapping
- javascript ES6模块化
热门文章
- 【ABAP系列】SAP ABAP 刷新SCREEN的方法
- java中线程同步的理解(非常通俗易懂)
- Struts学习(一)
- Two modules in a project cannot share the same content root报错解决方案
- 使用CyclicBarrier+线程池,按总页数分批次开多线程执行逻辑
- java基础语法详细介绍
- Linux——临界段,信号量,互斥锁,自旋锁,原子操作
- Python入门之 Python内置函数
- Let&#39;s encrypt 通配域名DNS验证方式的证书自动更新
- CodeForces - 714E + POJ - 3666 (dp严格单调递增与非严格单调递增)