喷气背包中的rotateAnimation构成

发布于 2025-02-06 08:26:55 字数 1133 浏览 1 评论 0原文

我从GitHub上的一个项目中进行了这种旋转态度,我想将相同的旋转施加到我的图像(指南针带有针头箭头的指南),

这是rotateanimation的参数:

公共rotateyaimation(float fromdegrees,float fromDegrees,float todegrees,float todegrees,float todegrees,int pivotxtype,float pivotxvalue,float pivotxvalue,int int int pivotxvalue,float to PivotyType,float PivotyValue)

这是我的代码:

        angleCompass.value = -angle
        val an = RotateAnimation(
            -currentAngle, -angle,
            Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
            0.5f
        )
        currentAngle = azimuth
        an.duration = 500
        an.repeatCount = 0
        an.fillAfter = true
        binding.imgCompass.startAnimation(an)


        val anim = RotateAnimation(
            -currentAngle + qiblaDir, -azimuth,
            Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
            0.5f
        )
        angleNeedle.value = -azimuth
        currentAngle = azimuth
        anim.duration = 500
        anim.repeatCount = 0
        anim.fillAfter = true
        binding.imgQiblaArrow.startAnimation(anim)

如何在撰写中应用相同的动画?

I have this RotateAnimation from a project on GitHub and I want to apply the same rotation to my Image (Compass with needle arrow inside)

Here are the parameters of RotateAnimation:

public RotateAnimation(float fromDegrees, float toDegrees, int pivotXType, float pivotXValue, int pivotYType, float pivotYValue)

Here is my code:

        angleCompass.value = -angle
        val an = RotateAnimation(
            -currentAngle, -angle,
            Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
            0.5f
        )
        currentAngle = azimuth
        an.duration = 500
        an.repeatCount = 0
        an.fillAfter = true
        binding.imgCompass.startAnimation(an)


        val anim = RotateAnimation(
            -currentAngle + qiblaDir, -azimuth,
            Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
            0.5f
        )
        angleNeedle.value = -azimuth
        currentAngle = azimuth
        anim.duration = 500
        anim.repeatCount = 0
        anim.fillAfter = true
        binding.imgQiblaArrow.startAnimation(anim)

How can I apply the same animation in compose?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

厌味 2025-02-13 08:26:55

简单的例子,但是您可以这样实现;

@Composable
fun AnimatableSurface() {
    val currentAngle = 0f
    val angle = 90f
    val rotateAnim = remember { Animatable(currentAngle) }
    LaunchedEffect(key1 = true){
        rotateAnim.animateTo(angle, tween(2000))
    }
    Surface(
        modifier = Modifier.size(100.dp).rotate(rotateAnim.value),
        color = Color.Red
    ) {}
}

Simple example, but you can achieve like this;

@Composable
fun AnimatableSurface() {
    val currentAngle = 0f
    val angle = 90f
    val rotateAnim = remember { Animatable(currentAngle) }
    LaunchedEffect(key1 = true){
        rotateAnim.animateTo(angle, tween(2000))
    }
    Surface(
        modifier = Modifier.size(100.dp).rotate(rotateAnim.value),
        color = Color.Red
    ) {}
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文