0Pricing
Jetpack Compose Academy · Pelajaran

Transformasi: Geser, Perbesar & Putar

Dukung gestur mencubit dan multi-sentuh.

Transformasi: Geser, Perbesar & Putar adalah pelajaran Jetpack Compose Academy gratis di CoddyKit. Ini adalah pelajaran 3 dari 4. Kamu bisa membaca pelajaran lengkapnya di bawah secara gratis — lalu praktikkan langsung di browser dengan editor kode bawaan dan tutor AI 24/7. Ini adalah bagian dari jalur belajar Jetpack Compose Academy, dan progresmu tersinkronisasi di web dan aplikasi CoddyKit. Kursus Jetpack Compose Academy mencakup 4 pelajaran total.

Bagian dari pelajaran ini belum diterjemahkan dan ditampilkan dalam bahasa Inggris.

Pinch, Zoom, Rotate

Some gestures use two fingers at once. Compose bundles pan, zoom, and rotate into a single helper called detectTransformGestures. 🤏

One Detector, Three Values

Inside pointerInput, detectTransformGestures hands you pan as an Offset, zoom as a Float scale, and rotation in degrees together.

detectTransformGestures { _, pan, zoom, rotation -> }

Store the Three States

Keep a scale, an offset, and a rotation in remembered state. Update each from the gesture so the element transforms live.

var scale by remember { mutableStateOf(1f) }

Multiply the Zoom

The zoom value is relative, so multiply it into your scale rather than replacing it. Pinch out grows, pinch in shrinks.

scale *= zoom

Add the Rotation

The rotation delta is in degrees per gesture step. Accumulate it so twisting two fingers spins your content smoothly.

angle += rotation

Pan Moves It Around

The pan Offset reports how far the gesture's center moved. Add it to your offset state to slide the content under the fingers.

offset += pan

Apply with graphicsLayer

The clean way to render transforms is the graphicsLayer modifier. Set scaleX, scaleY, rotationZ, and translation in one place.

Modifier.graphicsLayer(scaleX = scale, scaleY = scale, rotationZ = angle)

Translate Inside the Layer

Inside graphicsLayer, set translationX and translationY from your offset. It transforms without forcing a costly layout pass.

translationX = offset.x; translationY = offset.y

Clamp the Scale

Users will pinch wildly, so clamp your scale to sane bounds with coerceIn. This stops content from vanishing or filling the world.

scale = scale.coerceIn(0.5f, 5f)

Order of Operations

graphicsLayer applies scale, then rotation, then translation. Knowing this order helps you predict where transformed content lands.

Centered Around the Pivot

By default transforms pivot around the element's center. Adjust transformOrigin in graphicsLayer to zoom and rotate around another point.

Modifier.graphicsLayer(transformOrigin = TransformOrigin(0f, 0f))

Quick Check

How should you apply the incoming zoom value to your scale state?

Recap: Multi-Touch Magic

You used detectTransformGestures for pan, zoom, and rotate, then applied them through graphicsLayer with clamping. Pinch-to-zoom is yours. 🎉

Pertanyaan yang Sering Diajukan

Apakah pelajaran “Transformasi: Geser, Perbesar & Putar” gratis?

Ya — teks lengkap “Transformasi: Geser, Perbesar & Putar” gratis dibaca di sini di web. Untuk praktiknya secara interaktif (editor kode bawaan dan tutor AI 24/7) dan buka sisa kursus Jetpack Compose Academy, upgrade ke CoddyKit PRO. Kursus Jetpack Compose Academy mencakup 4 pelajaran total.

Apa yang akan aku pelajari di “Transformasi: Geser, Perbesar & Putar”?

Dukung gestur mencubit dan multi-sentuh. Kamu berlatih Jetpack Compose Academy dengan kode praktik yang langsung kamu jalankan di browser, dan tutor AI 24/7 menjawab pertanyaanmu saat kamu mengerjakan pelajaran ini.

Apakah aku perlu pengalaman untuk memulai Jetpack Compose Academy?

Tidak diperlukan pengalaman sebelumnya. Jetpack Compose Academy di CoddyKit dirancang untuk pemula hingga pelajar tingkat lanjut, jadi kamu bisa memulai di sini atau dari awal dan belajar sesuai kecepatan kamu sendiri. Ini adalah pelajaran 3 dari 4.

Berapa lama pelajaran “Transformasi: Geser, Perbesar & Putar” memakan waktu?

Sebagian besar pelajaran CoddyKit memakan waktu sekitar 5–10 menit. Setiap pelajaran ringkas dan interaktif, jadi kamu membuat kemajuan stabil dan melanjutkan dari tempat kamu tinggalkan di web dan aplikasi.

Bisakah aku menulis dan menjalankan kode dalam pelajaran Jetpack Compose Academy ini?

Ya. Setiap pelajaran Jetpack Compose Academy menyertakan editor kode bawaan, jadi kamu menulis dan menjalankan kode nyata langsung di browser dan mendapatkan umpan balik AI instan — tidak diperlukan penyiapan lokal.

Semua pelajaran dalam kursus ini

  1. pointerInput & detectTapGestures
  2. Seret, Usap & Lontar
  3. Transformasi: Geser, Perbesar & Putar
  4. Koneksi Gulir Bersarang
← Kembali ke Jetpack Compose Academy