[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6E6VC3B4MQER7F49G16G1B2":3,"skill-same:01M6E6VC3B4MQER7F49G16G1B2":67},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":37,"linkOnly":38,"markdownContent":39,"markdownBody":40,"frontMatter":41,"refName":44,"commitSha":45,"skillDirectory":46,"forksCount":47,"repositoryHtmlUrl":48,"repositoryHomepageUrl":49,"ownerHtmlUrl":50,"ownerBlogUrl":6,"ownerDescription":51,"updatedAt":52,"install":53,"resources":66},"01M6E6VC3B4MQER7F49G16G1B2","axiom-uikit-animation-debugging",null,"Use when CAAnimation completion handler doesn't fire, spring physics look wrong on device, animation duration mismatches actual time, gesture + animation interaction causes jank, or timing differs between simulator and real hardware - systematic CAAnimation diagnosis with CATransaction patterns, frame rate awareness, and device-specific behavior","ComeOnOliver\u002Fskillshub","ComeOnOliver","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F43215937?v=4","01M6E5JNFECJAAVFE0W7SMWWD2","Haoran Shu","01M6E5JNNDQS7AJZDYFQ8TPZCK",67,"MIT","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002FCharlesWiltgen\u002FAxiom\u002Faxiom-uikit-animation-debugging\u002FSKILL.md",[],[19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36],"axiom uikit animation debugging","Animation","uikit","debugging","hardware","timing","interaction","diagnosis","systematic","physics","time","patterns","device","look","use","behavior","spring","awareness","2026-11-10 10:12:30",false,"---\nname: axiom-uikit-animation-debugging\ndescription: Use when CAAnimation completion handler doesn't fire, spring physics look wrong on device, animation duration mismatches actual time, gesture + animation interaction causes jank, or timing differs between simulator and real hardware - systematic CAAnimation diagnosis with CATransaction patterns, frame rate awareness, and device-specific behavior\nlicense: MIT\nmetadata:\n  version: \"1.0.0\"\n---\n\n# UIKit Animation Debugging\n\n## Overview\n\nCAAnimation issues manifest as missing completion handlers, wrong timing, or jank under specific conditions. **Core principle** 90% of CAAnimation problems are CATransaction timing, layer state, or frame rate assumptions, not Core Animation bugs.\n\n## Red Flags — Suspect CAAnimation Issue\n\nIf you see ANY of these, suspect animation logic not device behavior:\n- Completion handler fires on simulator but not device\n- Animation duration (0.5s) doesn't match visual duration (1.2s)\n- Spring animation looks correct on iPhone 15 Pro but janky on older devices\n- Gesture + animation together causes stuttering (fine separately)\n- `[weak self]` in completion handler and you're not sure why\n- ❌ **FORBIDDEN** Hardcoding duration\u002Fvalues to \"match what actually happens\"\n  - This ships device-specific bugs to users on different hardware\n  - Do not rationalize this as a \"temporary fix\" or \"good enough\"\n\n**Critical distinction** Simulator often hides timing issues (60Hz only, no throttling). Real devices expose them (variable frame rate, CPU throttling, background pressure). **MANDATORY: Test on real device (oldest supported model) before shipping.**\n\n## Mandatory First Steps\n\n**ALWAYS run these FIRST** (before changing code):\n\n```swift\n\u002F\u002F 1. Check if completion is firing at all\nanimation.completion = { [weak self] finished in\n    print(\"? COMPLETION FIRED: finished=\\(finished)\")\n    guard let self = self else {\n        print(\"? SELF WAS NIL\")\n        return\n    }\n    \u002F\u002F original code\n}\n\n\u002F\u002F 2. Check actual duration vs declared\nlet startTime = Date()\nlet anim = CABasicAnimation(keyPath: \"position.x\")\nanim.duration = 0.5  \u002F\u002F Declared\nlayer.add(anim, forKey: \"test\")\n\nDispatchQueue.main.asyncAfter(deadline: .now() + 0.51) {\n    print(\"Elapsed: \\(Date().timeIntervalSince(startTime))\")  \u002F\u002F Actual\n}\n\n\u002F\u002F 3. Check what animations are active\nif let keys = layer.animationKeys() {\n    print(\"Active animations: \\(keys)\")\n    for key in keys {\n        if let anim = layer.animation(forKey: key) {\n            print(\"\\(key): duration=\\(anim.duration), removed=\\(anim.isRemovedOnCompletion)\")\n        }\n    }\n}\n\n\u002F\u002F 4. Check layer state\nprint(\"Layer speed: \\(layer.speed)\")  \u002F\u002F != 1.0 means timing is scaled\nprint(\"Layer timeOffset: \\(layer.timeOffset)\")  \u002F\u002F != 0 means animation is offset\n```\n\n#### What this tells you\n- **Completion print appears** → Handler fires, issue is in callback code\n- **Completion print missing** → Handler not firing, check CATransaction\u002Flayer state\n- **Elapsed time == declared** → Duration is correct, visual jank is from frames\n- **Elapsed time != declared** → CATransaction wrapping is changing duration\n- **layer.speed != 1.0** → Something is slowing animation\n- **Active animations list is long** → Multiple animations competing\n\n#### MANDATORY INTERPRETATION\n\nBefore changing ANY code, you must identify which ONE diagnostic is the root cause:\n\n1. If completion fires but elapsed time != declared duration → Apply Pattern 2 (CATransaction)\n2. If completion doesn't fire AND isRemovedOnCompletion is true → Apply Pattern 3\n3. If completion fires but visual is janky → **MUST profile with Instruments first**\n   - You cannot guess \"it's probably frames\" - prove it with data\n   - Profile > Core Animation instrument shows frame drops with certainty\n   - If you skip Instruments, you're guessing\n\n#### If diagnostics are contradictory or unclear\n- STOP. Do NOT proceed to patterns yet\n- Add more print statements to narrow the cause\n- Ask: \"The diagnostics show X and Y but Z doesn't match. What am I missing?\"\n- Profile with Instruments > Core Animation if unsure\n\n## Decision Tree\n\n```\nCAAnimation problem?\n├─ Completion handler never fires?\n│  ├─ On simulator only?\n│  │  └─ Simulator timing is different (60Hz). Test on real device.\n│  ├─ On real device only?\n│  │  ├─ Check: isRemovedOnCompletion and fillMode\n│  │  ├─ Check: CATransaction wrapping\n│  │  └─ Check: app goes to background during animation\n│  └─ On both simulator and device?\n│     ├─ Check: completion handler is set BEFORE adding animation\n│     └─ Check: [weak self] is actually captured (not nil before completion)\n│\n├─ Duration mismatch (declared != visual)?\n│  ├─ Is layer.speed != 1.0?\n│  │  └─ Something scaled animation duration. Find and fix.\n│  ├─ Is animation wrapped in CATransaction?\n│  │  └─ CATransaction.setAnimationDuration() overrides animation.duration\n│  └─ Is visual duration LONGER than declared?\n│     └─ Simulator (60Hz) vs device frame rate (120Hz). Recalculate for real hardware.\n│\n├─ Spring physics wrong on device?\n│  ├─ Are values hardcoded for one device?\n│  │  └─ Use device performance class, not model\n│  ├─ Are damping\u002Fstiffness values swapped with mass\u002Fstiffness?\n│  │  └─ Check CASpringAnimation parameter meanings\n│  └─ Does it work on simulator but not device?\n│     └─ Simulator uses 60Hz. Device may use 120Hz. Recalculate.\n│\n└─ Gesture + animation jank?\n   ├─ Are animations competing (same keyPath)?\n   │  └─ Remove old animation before adding new\n   ├─ Is gesture updating layer while animation runs?\n   │  └─ Use CADisplayLink for synchronized updates\n   └─ Is gesture blocking the main thread?\n      └─ Profile with Instruments > Core Animation\n```\n\n## Common Patterns\n\n### Pattern Selection Rules (MANDATORY)\n\n#### Apply ONE pattern at a time, in this order\n\n1. **Always start with Pattern 1** (Completion Handler Basics)\n   - If completion NEVER fires → Pattern 1\n   - Verify completion is set BEFORE add() with print statement (line 33)\n   - Only proceed to Pattern 2 if completion FIRES but timing is wrong\n\n2. **Then Pattern 2** (CATransaction duration mismatch)\n   - Only if completion fires but elapsed time != declared duration\n   - Check logs from Mandatory First Steps (line 40-47)\n\n3. **Then Pattern 3** (isRemovedOnCompletion)\n   - Only if animation completes but visual state reverts\n\n4. **Patterns 4-7** Apply based on specific symptom (see Decision Tree line 91+)\n\n#### FORBIDDEN\n- ❌ Applying multiple patterns at once (\"let me try Pattern 2 AND Pattern 4 together\")\n- ❌ Skipping Pattern 1 because \"I already know it's not that\"\n- ❌ Combining patterns without understanding why each is needed\n- ❌ Trying patterns randomly and hoping one works\n\n### Pattern 1: Completion Handler Basics\n\n#### ❌ WRONG (Handler set AFTER adding animation)\n```swift\nlayer.add(animation, forKey: \"myAnimation\")\nanimation.completion = { finished in  \u002F\u002F ❌ Too late!\n    print(\"Done\")\n}\n```\n\n#### ✅ CORRECT (Handler set BEFORE adding)\n```swift\nanimation.completion = { [weak self] finished in\n    print(\"? Animation finished: \\(finished)\")\n    guard let self = self else { return }\n    self.doNextStep()\n}\nlayer.add(animation, forKey: \"myAnimation\")\n```\n\n**Why** Completion handler must be set before animation is added to layer. Setting after does nothing.\n\n---\n\n### Pattern 2: CATransaction vs animation.duration\n\n#### ❌ WRONG (CATransaction overrides animation duration)\n```swift\nCATransaction.begin()\nCATransaction.setAnimationDuration(2.0)  \u002F\u002F ❌ Overrides all animations!\nlet anim = CABasicAnimation(keyPath: \"position\")\nanim.duration = 0.5  \u002F\u002F This is ignored\nlayer.add(anim, forKey: nil)\nCATransaction.commit()  \u002F\u002F Animation takes 2.0 seconds, not 0.5\n```\n\n#### ✅ CORRECT (Set duration on animation, not transaction)\n```swift\nlet anim = CABasicAnimation(keyPath: \"position\")\nanim.duration = 0.5\nlayer.add(anim, forKey: nil)\n\u002F\u002F No CATransaction wrapping\n```\n\n**Why** CATransaction.setAnimationDuration() affects ALL animations in the transaction block. Use it only if you want to change all animations uniformly.\n\n---\n\n### Pattern 3: isRemovedOnCompletion & fillMode\n\n#### ❌ WRONG (Animation disappears after completion)\n```swift\nlet anim = CABasicAnimation(keyPath: \"opacity\")\nanim.fromValue = 1.0\nanim.toValue = 0.0\nanim.duration = 0.5\nlayer.add(anim, forKey: nil)\n\u002F\u002F After 0.5s, animation is removed AND layer reverts to original state\n```\n\n#### ✅ CORRECT (Keep animation state)\n```swift\nanim.isRemovedOnCompletion = false\nanim.fillMode = .forwards  \u002F\u002F Keep final state after animation\nlayer.add(anim, forKey: nil)\n\u002F\u002F After 0.5s, animation state is preserved\n```\n\n**Why** By default, animations are removed and layer reverts. For permanent state changes, set `isRemovedOnCompletion = false` and `fillMode = .forwards`.\n\n---\n\n### Pattern 4: Weak Self in Completion (MANDATORY)\n\n#### ❌ FORBIDDEN (Strong self creates retain cycle)\n```swift\nanim.completion = { finished in\n    self.property = \"value\"  \u002F\u002F ❌ GUARANTEED retain cycle\n}\n```\n\n#### ✅ MANDATORY (Always use weak self)\n```swift\nanim.completion = { [weak self] finished in\n    guard let self = self else { return }\n    self.property = \"value\"  \u002F\u002F Safe to access\n}\n```\n\n#### Why this is MANDATORY, not optional\n- CAAnimation keeps completion handler alive until animation completes\n- Completion handler captures self strongly (unless explicitly weak)\n- Creates retain cycle: self → animation → completion → self\n- Memory leak occurs even if animation is short-lived (0.3s doesn't prevent it)\n\n#### FORBIDDEN rationalizations\n- ❌ \"Animation is short, so no retain cycle risk\"\n- ❌ \"I'll remove the animation manually, so it's fine\"\n- ❌ \"This code path only runs once\"\n\n#### ALWAYS use [weak self] in completion handlers. No exceptions.\n\n---\n\n### Pattern 5: Multiple Animations (Same keyPath)\n\n#### ❌ WRONG (Animations conflict)\n```swift\n\u002F\u002F Add animation 1\nlet anim1 = CABasicAnimation(keyPath: \"position.x\")\nanim1.toValue = 100\nlayer.add(anim1, forKey: \"slide\")\n\n\u002F\u002F Later, add animation 2\nlet anim2 = CABasicAnimation(keyPath: \"position.x\")\nanim2.toValue = 200\nlayer.add(anim2, forKey: \"slide\")  \u002F\u002F ❌ Same key, replaces anim1!\n```\n\n#### ✅ CORRECT (Remove before adding)\n```swift\nlayer.removeAnimation(forKey: \"slide\")  \u002F\u002F Remove old first\n\nlet anim2 = CABasicAnimation(keyPath: \"position.x\")\nanim2.toValue = 200\nlayer.add(anim2, forKey: \"slide\")\n```\n\nOr use unique keys:\n```swift\nlet anim1 = CABasicAnimation(keyPath: \"position.x\")\nlayer.add(anim1, forKey: \"slide_1\")\n\nlet anim2 = CABasicAnimation(keyPath: \"position.x\")\nlayer.add(anim2, forKey: \"slide_2\")  \u002F\u002F Different key\n```\n\n**Why** Adding animation with same key replaces previous animation. Either remove old animation or use unique keys.\n\n---\n\n### Pattern 6: CADisplayLink for Gesture + Animation Sync\n\n#### ❌ WRONG (Gesture updates directly, animation updates at different rate)\n```swift\nfunc handlePan(_ gesture: UIPanGestureRecognizer) {\n    let translation = gesture.translation(in: view)\n    view.layer.position.x = translation.x  \u002F\u002F ❌ Syncing issue\n}\n\n\u002F\u002F Separately:\nlet anim = CABasicAnimation(keyPath: \"position.x\")\nview.layer.add(anim, forKey: nil)  \u002F\u002F Jank from desync\n```\n\n#### ✅ CORRECT (Use CADisplayLink for synchronization)\n```swift\nvar displayLink: CADisplayLink?\n\nfunc startSyncedAnimation() {\n    displayLink = CADisplayLink(\n        target: self,\n        selector: #selector(updateAnimation)\n    )\n    displayLink?.add(to: .main, forMode: .common)\n}\n\n@objc func updateAnimation() {\n    \u002F\u002F Update gesture AND animation in same frame\n    let gesture = currentGesture\n    let position = calculatePosition(from: gesture)\n    layer.position = position  \u002F\u002F Synchronized update\n}\n```\n\n**Why** Gesture recognizer and CAAnimation may run at different frame rates. CADisplayLink syncs both to screen refresh rate.\n\n---\n\n### Pattern 7: Spring Animation Device Differences\n\n#### ❌ WRONG (Hardcoded for one device)\n```swift\nlet springAnim = CASpringAnimation()\nspringAnim.damping = 0.7  \u002F\u002F Hardcoded for iPhone 15 Pro\nspringAnim.stiffness = 100\nlayer.add(springAnim, forKey: nil)  \u002F\u002F Janky on iPhone 12\n```\n\n#### ✅ CORRECT (Adapt to device performance)\n```swift\nlet springAnim = CASpringAnimation()\n\n\u002F\u002F Use device performance class, not model\nif ProcessInfo.processInfo.processorCount >= 6 {\n    \u002F\u002F Modern A-series (A14+)\n    springAnim.damping = 0.7\n    springAnim.stiffness = 100\n} else {\n    \u002F\u002F Older A-series\n    springAnim.damping = 0.85\n    springAnim.stiffness = 80\n}\n\nlayer.add(springAnim, forKey: nil)\n```\n\n**Why** Spring physics feel different at 60Hz vs 120Hz. Use device class (core count, GPU) not model.\n\n---\n\n## Quick Reference Table\n\n| Issue | Check | Fix |\n|-------|-------|-----|\n| Completion never fires | Set handler BEFORE `add()` | Move `completion =` before `add()` |\n| Duration mismatch | Is CATransaction wrapping? | Remove CATransaction or remove animation from it |\n| Jank on older devices | Is value hardcoded? | Use `ProcessInfo` for device class |\n| Animation disappears | `isRemovedOnCompletion`? | Set to `false`, use `fillMode = .forwards` |\n| Gesture + animation jank | Synced updates? | Use `CADisplayLink` |\n| Multiple animations conflict | Same key? | Use unique keys or `removeAnimation()` first |\n| Weak self in handler | Completion captured correctly? | Always use `[weak self]` in completion |\n\n## When You're Stuck After 30 Minutes\n\nIf you've spent >30 minutes and the animation is still broken:\n\n#### STOP. You either\n1. Skipped a mandatory step (most common)\n2. Misinterpreted diagnostic output\n3. Applied wrong pattern for your symptom\n4. Are in the 5% edge case requiring Instruments profiling\n\n#### MANDATORY checklist before claiming \"skill didn't work\"\n\n- [ ] I ran ALL 4 diagnostic blocks from Mandatory First Steps (lines 28-63)\n- [ ] I pasted the EXACT output of diagnostics (logs, print statements)\n- [ ] I identified ONE root cause from \"What this tells you\" (lines 66-72)\n- [ ] I applied the FIRST matching pattern from Decision Tree (lines 91+)\n- [ ] I tested the pattern on a REAL device, not just simulator\n- [ ] I verified the pattern with print statements\u002Flogs showing the fix worked\n\n#### If ALL boxes are checked and still broken\n- You MUST profile with Instruments > Core Animation\n- Time cost: 30-60 minutes (unavoidable for edge cases)\n- Hardcoding, asyncAfter, or \"shipping and hoping\" are FORBIDDEN\n- Ask for guidance before adding any workarounds\n\n#### Time cost transparency\n- Pattern 1: 2-5 minutes\n- Pattern 2: 3-5 minutes\n- Instruments profiling: 30-60 minutes (for edge cases only)\n- Trying random fixes without profiling: 2-4 hours + risk of shipping broken\n\n## Common Mistakes\n\n❌ **Setting completion handler AFTER adding animation**\n- Completion is not set in time\n- Fix: Set completion BEFORE `layer.add()`\n\n❌ **Assuming simulator timing = device timing**\n- Simulator runs 60Hz, devices run 60Hz-120Hz\n- Fix: Test on real device before tuning duration\n\n❌ **Hardcoding device-specific values**\n- \"This value works on iPhone 15 Pro\" → fails on iPhone 12\n- Fix: Use `ProcessInfo.processInfo.processorCount` or test class\n\n❌ **Wrapping animation in CATransaction.setAnimationDuration()**\n- Overrides all animation durations in that transaction\n- Fix: Set duration on animation, not transaction\n\n❌ **FORBIDDEN: Using strong self in completion handler**\n- GUARANTEED retain cycle: self → animation → completion → self\n- Fix: ALWAYS use `[weak self]` with guard\n\n❌ **Not removing old animation before adding new**\n- Same keyPath replaces previous animation\n- Fix: `layer.removeAnimation(forKey:)` first or use unique keys\n\n❌ **Ignoring layer.speed and layer.timeOffset**\n- These scale animation timing invisibly\n- Fix: Check these values if timing is wrong\n\n## Real-World Impact\n\n**Before** CAAnimation debugging 2-4 hours per issue\n- Print everywhere, test on simulator, hardcode values, ship and hope\n- \"Maybe it's a device bug?\"\n- DispatchQueue.asyncAfter as fallback timer\n\n**After** 15-30 minutes with systematic diagnosis\n- Check completion handler setup (2 min)\n- Check CATransaction wrapping (3 min)\n- Check layer state and duration mismatch (5 min)\n- Identify root cause, apply pattern (5 min)\n- Test on real device (varies)\n\n**Key insight** CAAnimation issues are almost always CATransaction, layer state, or frame rate assumptions, never Core Animation bugs.\n\n---\n\n**Last Updated**: 2025-11-30\n**Status**: TDD-tested with pressure scenarios\n**Framework**: UIKit CAAnimation\n\n\n","# UIKit Animation Debugging\n\n## Overview\n\nCAAnimation issues manifest as missing completion handlers, wrong timing, or jank under specific conditions. **Core principle** 90% of CAAnimation problems are CATransaction timing, layer state, or frame rate assumptions, not Core Animation bugs.\n\n## Red Flags — Suspect CAAnimation Issue\n\nIf you see ANY of these, suspect animation logic not device behavior:\n- Completion handler fires on simulator but not device\n- Animation duration (0.5s) doesn't match visual duration (1.2s)\n- Spring animation looks correct on iPhone 15 Pro but janky on older devices\n- Gesture + animation together causes stuttering (fine separately)\n- `[weak self]` in completion handler and you're not sure why\n- ❌ **FORBIDDEN** Hardcoding duration\u002Fvalues to \"match what actually happens\"\n  - This ships device-specific bugs to users on different hardware\n  - Do not rationalize this as a \"temporary fix\" or \"good enough\"\n\n**Critical distinction** Simulator often hides timing issues (60Hz only, no throttling). Real devices expose them (variable frame rate, CPU throttling, background pressure). **MANDATORY: Test on real device (oldest supported model) before shipping.**\n\n## Mandatory First Steps\n\n**ALWAYS run these FIRST** (before changing code):\n\n```swift\n\u002F\u002F 1. Check if completion is firing at all\nanimation.completion = { [weak self] finished in\n    print(\"? COMPLETION FIRED: finished=\\(finished)\")\n    guard let self = self else {\n        print(\"? SELF WAS NIL\")\n        return\n    }\n    \u002F\u002F original code\n}\n\n\u002F\u002F 2. Check actual duration vs declared\nlet startTime = Date()\nlet anim = CABasicAnimation(keyPath: \"position.x\")\nanim.duration = 0.5  \u002F\u002F Declared\nlayer.add(anim, forKey: \"test\")\n\nDispatchQueue.main.asyncAfter(deadline: .now() + 0.51) {\n    print(\"Elapsed: \\(Date().timeIntervalSince(startTime))\")  \u002F\u002F Actual\n}\n\n\u002F\u002F 3. Check what animations are active\nif let keys = layer.animationKeys() {\n    print(\"Active animations: \\(keys)\")\n    for key in keys {\n        if let anim = layer.animation(forKey: key) {\n            print(\"\\(key): duration=\\(anim.duration), removed=\\(anim.isRemovedOnCompletion)\")\n        }\n    }\n}\n\n\u002F\u002F 4. Check layer state\nprint(\"Layer speed: \\(layer.speed)\")  \u002F\u002F != 1.0 means timing is scaled\nprint(\"Layer timeOffset: \\(layer.timeOffset)\")  \u002F\u002F != 0 means animation is offset\n```\n\n#### What this tells you\n- **Completion print appears** → Handler fires, issue is in callback code\n- **Completion print missing** → Handler not firing, check CATransaction\u002Flayer state\n- **Elapsed time == declared** → Duration is correct, visual jank is from frames\n- **Elapsed time != declared** → CATransaction wrapping is changing duration\n- **layer.speed != 1.0** → Something is slowing animation\n- **Active animations list is long** → Multiple animations competing\n\n#### MANDATORY INTERPRETATION\n\nBefore changing ANY code, you must identify which ONE diagnostic is the root cause:\n\n1. If completion fires but elapsed time != declared duration → Apply Pattern 2 (CATransaction)\n2. If completion doesn't fire AND isRemovedOnCompletion is true → Apply Pattern 3\n3. If completion fires but visual is janky → **MUST profile with Instruments first**\n   - You cannot guess \"it's probably frames\" - prove it with data\n   - Profile > Core Animation instrument shows frame drops with certainty\n   - If you skip Instruments, you're guessing\n\n#### If diagnostics are contradictory or unclear\n- STOP. Do NOT proceed to patterns yet\n- Add more print statements to narrow the cause\n- Ask: \"The diagnostics show X and Y but Z doesn't match. What am I missing?\"\n- Profile with Instruments > Core Animation if unsure\n\n## Decision Tree\n\n```\nCAAnimation problem?\n├─ Completion handler never fires?\n│  ├─ On simulator only?\n│  │  └─ Simulator timing is different (60Hz). Test on real device.\n│  ├─ On real device only?\n│  │  ├─ Check: isRemovedOnCompletion and fillMode\n│  │  ├─ Check: CATransaction wrapping\n│  │  └─ Check: app goes to background during animation\n│  └─ On both simulator and device?\n│     ├─ Check: completion handler is set BEFORE adding animation\n│     └─ Check: [weak self] is actually captured (not nil before completion)\n│\n├─ Duration mismatch (declared != visual)?\n│  ├─ Is layer.speed != 1.0?\n│  │  └─ Something scaled animation duration. Find and fix.\n│  ├─ Is animation wrapped in CATransaction?\n│  │  └─ CATransaction.setAnimationDuration() overrides animation.duration\n│  └─ Is visual duration LONGER than declared?\n│     └─ Simulator (60Hz) vs device frame rate (120Hz). Recalculate for real hardware.\n│\n├─ Spring physics wrong on device?\n│  ├─ Are values hardcoded for one device?\n│  │  └─ Use device performance class, not model\n│  ├─ Are damping\u002Fstiffness values swapped with mass\u002Fstiffness?\n│  │  └─ Check CASpringAnimation parameter meanings\n│  └─ Does it work on simulator but not device?\n│     └─ Simulator uses 60Hz. Device may use 120Hz. Recalculate.\n│\n└─ Gesture + animation jank?\n   ├─ Are animations competing (same keyPath)?\n   │  └─ Remove old animation before adding new\n   ├─ Is gesture updating layer while animation runs?\n   │  └─ Use CADisplayLink for synchronized updates\n   └─ Is gesture blocking the main thread?\n      └─ Profile with Instruments > Core Animation\n```\n\n## Common Patterns\n\n### Pattern Selection Rules (MANDATORY)\n\n#### Apply ONE pattern at a time, in this order\n\n1. **Always start with Pattern 1** (Completion Handler Basics)\n   - If completion NEVER fires → Pattern 1\n   - Verify completion is set BEFORE add() with print statement (line 33)\n   - Only proceed to Pattern 2 if completion FIRES but timing is wrong\n\n2. **Then Pattern 2** (CATransaction duration mismatch)\n   - Only if completion fires but elapsed time != declared duration\n   - Check logs from Mandatory First Steps (line 40-47)\n\n3. **Then Pattern 3** (isRemovedOnCompletion)\n   - Only if animation completes but visual state reverts\n\n4. **Patterns 4-7** Apply based on specific symptom (see Decision Tree line 91+)\n\n#### FORBIDDEN\n- ❌ Applying multiple patterns at once (\"let me try Pattern 2 AND Pattern 4 together\")\n- ❌ Skipping Pattern 1 because \"I already know it's not that\"\n- ❌ Combining patterns without understanding why each is needed\n- ❌ Trying patterns randomly and hoping one works\n\n### Pattern 1: Completion Handler Basics\n\n#### ❌ WRONG (Handler set AFTER adding animation)\n```swift\nlayer.add(animation, forKey: \"myAnimation\")\nanimation.completion = { finished in  \u002F\u002F ❌ Too late!\n    print(\"Done\")\n}\n```\n\n#### ✅ CORRECT (Handler set BEFORE adding)\n```swift\nanimation.completion = { [weak self] finished in\n    print(\"? Animation finished: \\(finished)\")\n    guard let self = self else { return }\n    self.doNextStep()\n}\nlayer.add(animation, forKey: \"myAnimation\")\n```\n\n**Why** Completion handler must be set before animation is added to layer. Setting after does nothing.\n\n---\n\n### Pattern 2: CATransaction vs animation.duration\n\n#### ❌ WRONG (CATransaction overrides animation duration)\n```swift\nCATransaction.begin()\nCATransaction.setAnimationDuration(2.0)  \u002F\u002F ❌ Overrides all animations!\nlet anim = CABasicAnimation(keyPath: \"position\")\nanim.duration = 0.5  \u002F\u002F This is ignored\nlayer.add(anim, forKey: nil)\nCATransaction.commit()  \u002F\u002F Animation takes 2.0 seconds, not 0.5\n```\n\n#### ✅ CORRECT (Set duration on animation, not transaction)\n```swift\nlet anim = CABasicAnimation(keyPath: \"position\")\nanim.duration = 0.5\nlayer.add(anim, forKey: nil)\n\u002F\u002F No CATransaction wrapping\n```\n\n**Why** CATransaction.setAnimationDuration() affects ALL animations in the transaction block. Use it only if you want to change all animations uniformly.\n\n---\n\n### Pattern 3: isRemovedOnCompletion & fillMode\n\n#### ❌ WRONG (Animation disappears after completion)\n```swift\nlet anim = CABasicAnimation(keyPath: \"opacity\")\nanim.fromValue = 1.0\nanim.toValue = 0.0\nanim.duration = 0.5\nlayer.add(anim, forKey: nil)\n\u002F\u002F After 0.5s, animation is removed AND layer reverts to original state\n```\n\n#### ✅ CORRECT (Keep animation state)\n```swift\nanim.isRemovedOnCompletion = false\nanim.fillMode = .forwards  \u002F\u002F Keep final state after animation\nlayer.add(anim, forKey: nil)\n\u002F\u002F After 0.5s, animation state is preserved\n```\n\n**Why** By default, animations are removed and layer reverts. For permanent state changes, set `isRemovedOnCompletion = false` and `fillMode = .forwards`.\n\n---\n\n### Pattern 4: Weak Self in Completion (MANDATORY)\n\n#### ❌ FORBIDDEN (Strong self creates retain cycle)\n```swift\nanim.completion = { finished in\n    self.property = \"value\"  \u002F\u002F ❌ GUARANTEED retain cycle\n}\n```\n\n#### ✅ MANDATORY (Always use weak self)\n```swift\nanim.completion = { [weak self] finished in\n    guard let self = self else { return }\n    self.property = \"value\"  \u002F\u002F Safe to access\n}\n```\n\n#### Why this is MANDATORY, not optional\n- CAAnimation keeps completion handler alive until animation completes\n- Completion handler captures self strongly (unless explicitly weak)\n- Creates retain cycle: self → animation → completion → self\n- Memory leak occurs even if animation is short-lived (0.3s doesn't prevent it)\n\n#### FORBIDDEN rationalizations\n- ❌ \"Animation is short, so no retain cycle risk\"\n- ❌ \"I'll remove the animation manually, so it's fine\"\n- ❌ \"This code path only runs once\"\n\n#### ALWAYS use [weak self] in completion handlers. No exceptions.\n\n---\n\n### Pattern 5: Multiple Animations (Same keyPath)\n\n#### ❌ WRONG (Animations conflict)\n```swift\n\u002F\u002F Add animation 1\nlet anim1 = CABasicAnimation(keyPath: \"position.x\")\nanim1.toValue = 100\nlayer.add(anim1, forKey: \"slide\")\n\n\u002F\u002F Later, add animation 2\nlet anim2 = CABasicAnimation(keyPath: \"position.x\")\nanim2.toValue = 200\nlayer.add(anim2, forKey: \"slide\")  \u002F\u002F ❌ Same key, replaces anim1!\n```\n\n#### ✅ CORRECT (Remove before adding)\n```swift\nlayer.removeAnimation(forKey: \"slide\")  \u002F\u002F Remove old first\n\nlet anim2 = CABasicAnimation(keyPath: \"position.x\")\nanim2.toValue = 200\nlayer.add(anim2, forKey: \"slide\")\n```\n\nOr use unique keys:\n```swift\nlet anim1 = CABasicAnimation(keyPath: \"position.x\")\nlayer.add(anim1, forKey: \"slide_1\")\n\nlet anim2 = CABasicAnimation(keyPath: \"position.x\")\nlayer.add(anim2, forKey: \"slide_2\")  \u002F\u002F Different key\n```\n\n**Why** Adding animation with same key replaces previous animation. Either remove old animation or use unique keys.\n\n---\n\n### Pattern 6: CADisplayLink for Gesture + Animation Sync\n\n#### ❌ WRONG (Gesture updates directly, animation updates at different rate)\n```swift\nfunc handlePan(_ gesture: UIPanGestureRecognizer) {\n    let translation = gesture.translation(in: view)\n    view.layer.position.x = translation.x  \u002F\u002F ❌ Syncing issue\n}\n\n\u002F\u002F Separately:\nlet anim = CABasicAnimation(keyPath: \"position.x\")\nview.layer.add(anim, forKey: nil)  \u002F\u002F Jank from desync\n```\n\n#### ✅ CORRECT (Use CADisplayLink for synchronization)\n```swift\nvar displayLink: CADisplayLink?\n\nfunc startSyncedAnimation() {\n    displayLink = CADisplayLink(\n        target: self,\n        selector: #selector(updateAnimation)\n    )\n    displayLink?.add(to: .main, forMode: .common)\n}\n\n@objc func updateAnimation() {\n    \u002F\u002F Update gesture AND animation in same frame\n    let gesture = currentGesture\n    let position = calculatePosition(from: gesture)\n    layer.position = position  \u002F\u002F Synchronized update\n}\n```\n\n**Why** Gesture recognizer and CAAnimation may run at different frame rates. CADisplayLink syncs both to screen refresh rate.\n\n---\n\n### Pattern 7: Spring Animation Device Differences\n\n#### ❌ WRONG (Hardcoded for one device)\n```swift\nlet springAnim = CASpringAnimation()\nspringAnim.damping = 0.7  \u002F\u002F Hardcoded for iPhone 15 Pro\nspringAnim.stiffness = 100\nlayer.add(springAnim, forKey: nil)  \u002F\u002F Janky on iPhone 12\n```\n\n#### ✅ CORRECT (Adapt to device performance)\n```swift\nlet springAnim = CASpringAnimation()\n\n\u002F\u002F Use device performance class, not model\nif ProcessInfo.processInfo.processorCount >= 6 {\n    \u002F\u002F Modern A-series (A14+)\n    springAnim.damping = 0.7\n    springAnim.stiffness = 100\n} else {\n    \u002F\u002F Older A-series\n    springAnim.damping = 0.85\n    springAnim.stiffness = 80\n}\n\nlayer.add(springAnim, forKey: nil)\n```\n\n**Why** Spring physics feel different at 60Hz vs 120Hz. Use device class (core count, GPU) not model.\n\n---\n\n## Quick Reference Table\n\n| Issue | Check | Fix |\n|-------|-------|-----|\n| Completion never fires | Set handler BEFORE `add()` | Move `completion =` before `add()` |\n| Duration mismatch | Is CATransaction wrapping? | Remove CATransaction or remove animation from it |\n| Jank on older devices | Is value hardcoded? | Use `ProcessInfo` for device class |\n| Animation disappears | `isRemovedOnCompletion`? | Set to `false`, use `fillMode = .forwards` |\n| Gesture + animation jank | Synced updates? | Use `CADisplayLink` |\n| Multiple animations conflict | Same key? | Use unique keys or `removeAnimation()` first |\n| Weak self in handler | Completion captured correctly? | Always use `[weak self]` in completion |\n\n## When You're Stuck After 30 Minutes\n\nIf you've spent >30 minutes and the animation is still broken:\n\n#### STOP. You either\n1. Skipped a mandatory step (most common)\n2. Misinterpreted diagnostic output\n3. Applied wrong pattern for your symptom\n4. Are in the 5% edge case requiring Instruments profiling\n\n#### MANDATORY checklist before claiming \"skill didn't work\"\n\n- [ ] I ran ALL 4 diagnostic blocks from Mandatory First Steps (lines 28-63)\n- [ ] I pasted the EXACT output of diagnostics (logs, print statements)\n- [ ] I identified ONE root cause from \"What this tells you\" (lines 66-72)\n- [ ] I applied the FIRST matching pattern from Decision Tree (lines 91+)\n- [ ] I tested the pattern on a REAL device, not just simulator\n- [ ] I verified the pattern with print statements\u002Flogs showing the fix worked\n\n#### If ALL boxes are checked and still broken\n- You MUST profile with Instruments > Core Animation\n- Time cost: 30-60 minutes (unavoidable for edge cases)\n- Hardcoding, asyncAfter, or \"shipping and hoping\" are FORBIDDEN\n- Ask for guidance before adding any workarounds\n\n#### Time cost transparency\n- Pattern 1: 2-5 minutes\n- Pattern 2: 3-5 minutes\n- Instruments profiling: 30-60 minutes (for edge cases only)\n- Trying random fixes without profiling: 2-4 hours + risk of shipping broken\n\n## Common Mistakes\n\n❌ **Setting completion handler AFTER adding animation**\n- Completion is not set in time\n- Fix: Set completion BEFORE `layer.add()`\n\n❌ **Assuming simulator timing = device timing**\n- Simulator runs 60Hz, devices run 60Hz-120Hz\n- Fix: Test on real device before tuning duration\n\n❌ **Hardcoding device-specific values**\n- \"This value works on iPhone 15 Pro\" → fails on iPhone 12\n- Fix: Use `ProcessInfo.processInfo.processorCount` or test class\n\n❌ **Wrapping animation in CATransaction.setAnimationDuration()**\n- Overrides all animation durations in that transaction\n- Fix: Set duration on animation, not transaction\n\n❌ **FORBIDDEN: Using strong self in completion handler**\n- GUARANTEED retain cycle: self → animation → completion → self\n- Fix: ALWAYS use `[weak self]` with guard\n\n❌ **Not removing old animation before adding new**\n- Same keyPath replaces previous animation\n- Fix: `layer.removeAnimation(forKey:)` first or use unique keys\n\n❌ **Ignoring layer.speed and layer.timeOffset**\n- These scale animation timing invisibly\n- Fix: Check these values if timing is wrong\n\n## Real-World Impact\n\n**Before** CAAnimation debugging 2-4 hours per issue\n- Print everywhere, test on simulator, hardcode values, ship and hope\n- \"Maybe it's a device bug?\"\n- DispatchQueue.asyncAfter as fallback timer\n\n**After** 15-30 minutes with systematic diagnosis\n- Check completion handler setup (2 min)\n- Check CATransaction wrapping (3 min)\n- Check layer state and duration mismatch (5 min)\n- Identify root cause, apply pattern (5 min)\n- Test on real device (varies)\n\n**Key insight** CAAnimation issues are almost always CATransaction, layer state, or frame rate assumptions, never Core Animation bugs.\n\n---\n\n**Last Updated**: 2025-11-30\n**Status**: TDD-tested with pressure scenarios\n**Framework**: UIKit CAAnimation\n\n\n",{"name":5,"license":15,"metadata":42,"description":7},{"version":43},"1.0.0","main","def8531e65114c0fca8fb8551c1871ee0eed705c","skills\u002FCharlesWiltgen\u002FAxiom\u002Faxiom-uikit-animation-debugging",24,"https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub","https:\u002F\u002Fskillshub.wtf","https:\u002F\u002Fgithub.com\u002FComeOnOliver","AI & Blockchain Engineer\r\n","2026-06-24 22:07:19",{"source":8,"skillName":5,"commands":54,"prompt":64,"zipAvailable":65},[55,58,61],{"tool":56,"command":57},"npx","npx skills add ComeOnOliver\u002Fskillshub --skill axiom-uikit-animation-debugging",{"tool":59,"command":60},"bunx","bunx skills add ComeOnOliver\u002Fskillshub --skill axiom-uikit-animation-debugging",{"tool":62,"command":63},"pnpm","pnpm dlx skills add ComeOnOliver\u002Fskillshub --skill axiom-uikit-animation-debugging","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002FCharlesWiltgen\u002FAxiom\u002Faxiom-uikit-animation-debugging\u002FSKILL.md",true,[],[68,77,86,95,101,107],{"skillNo":69,"name":70,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":71,"categories":72,"keywords":73,"publishedAt":37},"01M6FKJN13GMG4KY57J3QD8GY5","model-hierarchy-skill","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzscole\u002Fmodel-hierarchy-skill\u002Fmodel-hierarchy-skill\u002FSKILL.md",[],[74,75,76],"model","model hierarchy","model hierarchy skill",{"skillNo":78,"name":79,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":80,"categories":81,"keywords":82,"publishedAt":37},"01M6FKJJJ6GCAMR4PPPRD12M5X","zoom-mcp","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fzoom-mcp\u002FSKILL.md",[],[83,84,85],"MCP","zoom","zoom mcp",{"skillNo":87,"name":88,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":89,"categories":90,"keywords":91,"publishedAt":37},"01M6FKJE3KYT3KPEZMEEHYKA6K","zoom-apps-sdk","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fzoom-apps-sdk\u002FSKILL.md",[],[92,93,94,84],"sdk","zoom apps sdk","apps",{"skillNo":96,"name":97,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":98,"categories":99,"keywords":100,"publishedAt":37},"01M6FKJ9EDH9Q5VWDF8HAJRSP0","windows","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fwindows\u002FSKILL.md",[],[97],{"skillNo":102,"name":103,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":104,"categories":105,"keywords":106,"publishedAt":37},"01M6FKJ666BEEFC3AE9GJ72Q93","whiteboard","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fwhiteboard\u002FSKILL.md",[],[103],{"skillNo":108,"name":109,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":110,"categories":111,"keywords":112,"publishedAt":37},"01M6FKJ21WFCDGTJQ2Q91T9DVW","websockets","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fwebsockets\u002FSKILL.md",[],[109]]