在 Y 轴上旋转可组合项(jetpack compose)而不拉伸它

问题描述 投票:0回答:1

我有一张可组合的命名卡,其中包含大量员工/学生的身份信息, 我想添加旋转卡的功能,以便背面可读。我用以下方法做到了

 var rotation by remember { mutableFloatStateOf(0f) }
    Box(
      modifier = Modifier
          .padding(paddingValues = padding)
          .pointerInput(key1 = null) {
              detectHorizontalDragGestures { change, dragAmount ->
                  rotation -= dragAmount
                  if (rotation >= 360) {
                      rotation = 0f
                  }
              }
          },
      contentAlignment = Alignment.Center,
    ) {
      Card(
        card = card,
        modifier = Modifier
          .graphicsLayer {
            rotationY = rotation
          },
      )
    }

How the card is show on the screen

事情是,即使这有效,并且可组合项旋转,旋转将其拉伸到整个屏幕高度,所附的屏幕截图显示了这一点。有没有办法可以在 Y 轴上旋转卡片而不使其拉伸?

android kotlin 3d android-jetpack-compose jetpack
1个回答
0
投票

好的,感谢@Chirag Thummar,我发现我可以在图形层中使用

cameraDistance
来调整可组合项的视口距离,这样卡片就不会拉伸得太多。 18对我来说是最甜蜜的时刻

    var rotation by remember { mutableFloatStateOf(0f) }
Card(
            card = card,
            modifier = Modifier
              .graphicsLayer {
                rotationY = rotation
                cameraDistance = 18 * density
              },
          )
© www.soinside.com 2019 - 2024. All rights reserved.