หากต้องการตรวจจับท่าทางสัมผัสแบบมัลติทัชที่ใช้สำหรับการแพน ซูม และหมุน คุณสามารถใช้ตัวปรับแต่ง transformable ได้ ตัวแก้ไขนี้ไม่ได้เปลี่ยนรูปแบบองค์ประกอบด้วยตัวเอง แต่จะตรวจจับท่าทางสัมผัสเท่านั้น
@Composable private fun TransformableSample() { // set up all transformation states var scale by remember { mutableFloatStateOf(1f) } var rotation by remember { mutableFloatStateOf(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() ) }
หากต้องการรวมการซูม การเลื่อน และการหมุนเข้ากับท่าทางสัมผัสอื่นๆ คุณสามารถใช้ตัวตรวจจับ PointerInputScope.detectTransformGestures ได้
แนะนำสำหรับคุณ
- หมายเหตุ: ข้อความลิงก์จะแสดงเมื่อ JavaScript ปิดอยู่
- ทำความเข้าใจท่าทางสัมผัส