【发布时间】:2022-04-13 23:07:47
【问题描述】:
我试图在 jetpack compose 中做一个指南针。但是我在制作动画时遇到了问题。
我有一个@Composable,它可以让用户手机旋转并以相反的方向旋转指南针图像。我像这样使用animateFloatAsState:
val angle: Float by animateFloatAsState(
targetValue = -rotation, \\ rotation is retrieved as argument
animationSpec = tween(
durationMillis = UPDATE_FREQUENCY, \\ rotation is retrieved with this frequency
easing = LinearEasing
)
)
Image(
modifier = Modifier.rotate(angle),
// rest of the code for image
)
一切看起来都很好,但是当rotation 从1 更改为359 或以相反的方式时,就会出现问题。动画不会向左旋转2 度,而是向右旋转358 度,这看起来很糟糕。有什么方法可以使用最短的方式制作旋转动画?
【问题讨论】:
标签: android kotlin animation android-jetpack-compose