マルチタッチ: パン、ズーム、回転

パン、ズーム、回転に使用されるマルチタッチ操作を検出するには、transformable 修飾子を使用します。この修飾子は、それ自体では要素を変換せず、操作の検出のみを行います。

@Composable
private fun TransformableSample() {
   
// set up all transformation states
   
var scale by remember { mutableStateOf(1f) }
   
var rotation by remember { mutableStateOf(0f) }
   
var offset by remember { mutableStateOf(Offset.Zero) }
   
val state = rememberTransformableState { zoomChange, offsetChange, rotationChange ->
        scale
*= zoomChange
        rotation
+= rotationChange
        offset
+= offsetChange
   
}
   
Box(
       
Modifier
           
// apply other transformations like rotation and zoom
           
// on the pizza slice emoji
           
.graphicsLayer(
                scaleX
= scale,
                scaleY
= scale,
                rotationZ
= rotation,
                translationX
= offset.x,
                translationY
= offset.y
           
)
           
// add transformable to listen to multitouch transformation events
           
// after offset
           
.transformable(state = state)
           
.background(Color.Blue)
           
.fillMaxSize()
   
)
}

マルチタッチ操作(パン、ズーム、回転)に応答する UI 要素

ズーム、パン、回転を他の操作と組み合わせる必要がある場合は、PointerInputScope.detectTransformGestures 検出機能を使用できます。

現在、おすすめはありません。

Google アカウントにしてください。