gpt4 book ai didi

javascript - 在 React-Native 中手动设置不透明度的音量 onPress of TouchableOpacity

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:58:29 24 4
gpt4 key购买 nike

我想弄清楚如何更改 React-Native 的 TouchableOpacity 组件的不透明度,这意味着我不喜欢执行按下时不透明度的默认值,我希望不透明度为不那么透明。

根据documentation为此目的 Animated API应该使用:

Opacity is controlled by wrapping the children in an Animated.View, which is added to the view hierarchy. Be aware that this can affect layout.

所以,我做到了,这就是它的样子:

<Animated.View style={{ opacity: this.state.opacity._value }}>
<TouchableOpacity
onPress={this.hideKeyboard.bind(this)}
style={{ opacity: this.state.opacity._value }}
>
<Text style={buttonTextStyle}>Cancel</Text>
</TouchableOpacity>
</Animated.View>

hideKeyboard 方法,在按下时被调用,从内部调用 changeOpacity 方法,这就是它的样子:

changeOpacity() {
Animated.timing(
this.state.opacity,
{
toValue: this.state.opacity === 1 ? 0 : 1,
duration: 500
}
).start();
}

this.state.opacity 在构造函数中声明:

constructor(props) {
super(props);
this.state = { opacity: new Animated.Value(1) };
}

拥有所有这些,行为(TouchableOpacity 的不透明度 onPress 的音量)不会改变,它仍然保持默认。文档也含糊地介绍了setOpacityTo方法,但是由于文档中提供的描述太透彻,我不知道如何使用它。如何手动配置不透明度?

最佳答案

你试过吗

<TouchableOpacity 
activeOpacity={.7} // default is .2
... other props here
/>

关于javascript - 在 React-Native 中手动设置不透明度的音量 onPress of TouchableOpacity,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45481957/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com