【发布时间】:2022-11-10 16:57:51
【问题描述】:
你能告诉我为什么当我使用val animateAngle: Float by transition.animateFloat 而不是val animateAngle by animateFloatAsState 时它会停止工作吗?
单击按钮时,变量rotated 似乎没有更新。
var rotated by remember {
mutableStateOf(false)
}
val transition = updateTransition(
targetState = rotated,
label = "Rotate"
)
val animateAngle: Float by transition.animateFloat(
transitionSpec = {
tween(2000)
},
label = "Rotate box"
) { state ->
when(state){
rotated -> 360f
else -> 0f
}
}
Column (
) {
Image(
painter = painterResource(id = R.drawable.propeller),
contentDescription = "fan",
modifier = Modifier
.rotate(animateAngle)
.padding(30.dp)
.size(100.dp))
Button(
onClick = {
rotated = !rotated
},
) {
Text(text = "Rotate Box")
}
}
【问题讨论】:
标签: android function android-jetpack-compose jetpack-compose-animation