Multitouch: Panning, zooming, rotating

To detect multitouch gestures used for panning, zooming and rotating, you can use the transformable modifier. This modifier does not transform elements by itself, it only detects the gestures.

@Composable
privatefunTransformableSample(){
// set up all transformation states
varscalebyremember{mutableFloatStateOf(1f)}
varrotationbyremember{mutableFloatStateOf(0f)}
varoffsetbyremember{mutableStateOf(Offset.Zero)}
valstate=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()
)
}

A UI element responding to multitouch gestures—panning, zooming, and rotating

If you need to combine zooming, panning and rotation with other gestures, you can use the PointerInputScope.detectTransformGestures detector.

Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.

Last updated 2025年12月29日 UTC.