0Pricing
SwiftUI Academy · درس

الرسوم المتحركة الصريحة باستخدام withAnimation

غلّف تغييرات الحالة للتحكم في التوقيت

الرسوم المتحركة الصريحة باستخدام withAnimation درس مجاني في SwiftUI Academy على CoddyKit. هذا هو الدرس 2 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في SwiftUI Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة SwiftUI Academy 4 دروس في المجموع.

بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.

When You Want Control

Sometimes you want to decide exactly which change animates. withAnimation wraps a state change so its results tween.

The withAnimation Block

You put your state mutation inside withAnimation. Every view update caused by that change animates together.

withAnimation {
    isExpanded.toggle()
}

Explicit vs Implicit

Implicit animation lives on the view; explicit animation lives at the change site. You choose what animates by where you mutate.

Add a Curve

Pass a curve to withAnimation just like the modifier. The animation argument shapes the timing of the whole block.

withAnimation(.easeInOut(duration: 0.3)) {
    show.toggle()
}

Trigger from a Button

A common pattern is wrapping a toggle in a Button action so a tap animates the resulting layout change.

Button("Toggle") {
    withAnimation { open.toggle() }
}

Many Views, One Block

If one state change affects several views, withAnimation animates them all in sync from a single wrapped mutation.

Use a Spring Feel

Springs give natural, bouncy motion. Pass .spring to withAnimation for UI that feels physical and responsive.

withAnimation(.spring) {
    selected = id
}

Animate Conditional Views

Toggling a boolean that adds or removes a view inside withAnimation animates its appearance, not just its properties.

withAnimation {
    showDetail = true
}

Return a Value

withAnimation can return the value its closure produces, so you can animate and read a result in one expression.

Completion Handling

Newer APIs let you run code after the motion finishes via a completion callback on withAnimation, great for chaining steps.

Keep Blocks Focused

Only put the change you want to animate inside the block. Unrelated work outside withAnimation stays instant and clean.

Quick Check

What is the key difference between the two animation styles?

Recap: withAnimation

You saw how withAnimation wraps a state change so every resulting update tweens together. It gives precise control over what animates. 👍

الأسئلة الشائعة

هل درس «الرسوم المتحركة الصريحة باستخدام withAnimation» مجاني؟

نعم — نص درس «الرسوم المتحركة الصريحة باستخدام withAnimation» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة SwiftUI Academy، انتقل إلى CoddyKit PRO. تتضمن دورة SwiftUI Academy 4 دروس في المجموع.

ماذا ستتعلم في «الرسوم المتحركة الصريحة باستخدام withAnimation»؟

غلّف تغييرات الحالة للتحكم في التوقيت تتمرن على SwiftUI Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ SwiftUI Academy؟

لا تُشترط خبرة سابقة. SwiftUI Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 2 من أصل 4.

كم من الوقت يستغرق درس «الرسوم المتحركة الصريحة باستخدام withAnimation»؟

معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.

هل يمكنني كتابة وتشغيل أكواد في درس SwiftUI Academy هذا؟

نعم. كل درس في SwiftUI Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. الرسوم المتحركة الضمنية
  2. الرسوم المتحركة الصريحة باستخدام withAnimation
  3. انتقالات الإدراج والإزالة
  4. منحنيات التوقيت الزنبركية والمخصصة
← العودة إلى SwiftUI Academy