@Composable
fun RepeatingRotationAnimation() {
var visible by remember { mutableStateOf(true)
}
val scale by animateFloatAsState(targetValue = if (visible) 0.0f else 360.0f,animationSpec =
repeatable(iterations = 2,
animation = tween(durationMillis = 2000),
repeatMode = RepeatMode.Reverse
)
)
Column(horizontalAlignment = Alignment.Start) {
Box(
modifier = Modifier
.size(200.dp)
.graphicsLayer {
rotationZ =scale
}
.background(Color.Blue),
contentAlignment = Alignment.Center
) {
Text(text = "Hello", color = Color.White)
}
}
Spacer(modifier = Modifier.height(20.dp))
Button(onClick = { visible = !visible }) {
Text(text = if (visible) "Hide" else "Show")
}
}
03-30
9137
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
08-14
707
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
01-13