Để phát hiện cử chỉ cảm ứng đa điểm dùng để kéo (hình ảnh), thu phóng và xoay, bạn có thể sử dụng phương thức sửa đổi transformable. Phương thức sửa đổi này không tự chuyển đổi phần tử mà chỉ phát hiện cử chỉ.
@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() ) }
Nếu cần kết hợp cử chỉ thu phóng, kéo (hình ảnh) và xoay với các cử chỉ khác, bạn có thể sử dụng trình phát hiện PointerInputScope.detectTransformGestures.
Đề xuất cho bạn
- Lưu ý: văn bản có đường liên kết sẽ hiện khi JavaScript tắt
- Tìm hiểu về cử chỉ