react-native - 在 React Native 中使图像变小,大于变大,恢复到正常动画
问题描述
我需要制作一个动画,这会使图像变小,然后将图像变大一点然后恢复正常,当用户按下按钮时,这个动画应该每次重复。
这是我已经拥有的,目前它使图像更小。之后如何使它变大然后再恢复到正常大小?
class ReflectionScreen extends React.Component {
constructor(props) {
super(props)
this.animatedValue = new Animated.Value(0)
}
handleAnimation = () => {
Animated.timing(this.animatedValue, {
toValue: 1,
duration: 1000,
easing: Easing.ease
}).start()
}
render() {
<TouchableOpacity style={styles.handContainer} onPress={this.goIncrement}>
<Animated.Image
source={require('../images/tapHand.png')}
style={
[styles.imageHand,
{transform: [
{
translateX: this.animatedValue.interpolate({
inputRange: [0, 1],
outputRange: [0, 0.7]
})
},
{
translateY: this.animatedValue.interpolate({
inputRange: [0, 1],
outputRange: [0, 0.7]
})
},
{
scaleX: this.animatedValue.interpolate({
inputRange: [0, 1],
outputRange: [1, 0.7]
})
},
{
scaleY: this.animatedValue.interpolate({
inputRange: [0, 1],
outputRange: [1, 0.7]
})
},
{perspective: 1000}
]
}
]}
/>
</TouchableOpacity>
}
)}
}
解决方案
expand = () => {
Animated.timing(this.animatedValue, {
toValue: 1,
duration: 1000,
easing: Easing.ease
}).start(this.shrink)
}
shrink = () => {
Animated.timing(this.animatedValue, {
toValue: 1,
duration: 1000,
easing: Easing.ease
}).start(this.expand)
}
在里面调用回调函数start
,然后反转变换
this.animatedValue.interpolate({
inputRange: [0, 1],
outputRange: [0.7, 1.3]
})
...
推荐阅读
- selenium - 需要使用 Selenium 设置 Chromium Edge 浏览器的下载目录
- python - 为指定的列范围计算所有行中的非 0 值 - Python Pandas
- python - Tkinter 冻结多个线程
- mysql - 如何在 CTE 中使用 DELETE 和 UPDATE?
- ios - 如何使用单独的文件夹将 react-native 集成到 iOS。(不在反应根目录内)。?
- typescript - 如何在 Angular 7 上为国家/地区名称执行函数返回码?
- elasticsearch - 以反应方式使用弹簧数据弹性搜索保存记录通量
- c# - 我们如何只处理基类中的数据而不将它们克隆到派生类中?
- arrays - 使用 2d 数组作为 4d 数组的索引
- python - 在 Google Cloud Functions 上执行 shell 脚本