Skip to content

Latest commit

Β 

History

History
62 lines (35 loc) Β· 6.2 KB

TIL_2022:10:22_making_core_animation.md

File metadata and controls

62 lines (35 loc) Β· 6.2 KB

Today I Learned


2022.10.22 (ν† )

였늘의 μ• λ‹ˆλ©”μ΄μ…˜μ€ 아직 μ„±κ³΅ν•˜μ§€ λͺ»ν–ˆμŠ΅λ‹ˆλ‹€. γ…  거의 80%κ°€λŸ‰ μ„±κ³΅ν•œ 것 같은데 λ§€λ„λŸ½κ²Œ 이어지지가 μ•Šμ•„μ„œ μ’€ 더 손봐야할 것 κ°™μ•„μš”. κ³΅λΆ€ν•œ λ‚΄μš©μ€ λΈ”λ‘œκ·Έμ— μž‘μ„±ν–ˆμŠ΅λ‹ˆλ‹€. (μ—°μŠ΅μ΄μ—ˆμ„ 뿐 μ§„μ§œ κ΅¬ν˜„ν•  μ• λ‹ˆλ©”μ΄μ…˜μ€ μ•„λ‹ˆμ—μš”.)

KeyFrameAnimation 클래슀의 ν”„λ‘œνΌν‹°λ“€μ„ μ‚΄νŽ΄λ³΄κ²Œ λ˜μ—ˆμŠ΅λ‹ˆλ‹€. fillMode / keyTimes / timeOFfset λ“±λ“±.. μ• λ‹ˆλ©”μ΄μ…˜ μ‹œκ°„κ³Ό κ΄€λ ¨λœ ν”„λ‘œνΌν‹°λ“€μ΄ λ§Žμ•„μ„œ Core Animation의 μ‹œκ°„κ³Ό κ΄€λ ¨λœ λ¬Έμ„œλ₯Ό μ½μ–΄λ΄€μŠ΅λ‹ˆλ‹€. 근데 이 λ‚΄μš©μ΄ 쑰금 μ–΄λ ΅κ³  λ³΅μž‘ν•΄μ„œ μ „λΆ€λŠ” μ΄ν•΄ν•˜μ§„ λͺ»ν–ˆμ§€λ§Œ 내일도 μ½μ–΄λ΄μ„œ λ˜λ„λ‘ λ‹€ 이해해야 ν•  것 κ°™μŠ΅λ‹ˆλ‹Ή


KeyframeAnimation

  • values : An array of objects that specify the keyframe values to use for the animation. μ• λ‹ˆλ©”μ΄μ…˜μ— μ‚¬μš©λ  keyframe 값듀을 μ§€μ •ν•΄μ€λ‹ˆλ‹€. CAKeyframeAnimationμ—μ„œ μ• λ‹ˆλ©”μ΄μ…˜μ„ μ£ΌκΈ° μœ„ν•΄μ„œ κΌ­ ν•„μš”ν•œ κ°’μž…λ‹ˆλ‹€. 이 값은 path ν”„λ‘œνΌν‹°κ°€ nil일 λ•Œλ§Œ μ‚¬μš©κ°€λŠ₯ν•©λ‹ˆλ‹€! λ™μ‹œμ— μ‚¬μš©ν•˜λ©΄ X.

  • keyTimes : An optional array of NSNumber objects that define the time at which to apply a given keyframe segment. 0~1 μ‚¬μ΄μ˜ 숫자둜 이루어진 λ°°μ—΄μž…λ‹ˆλ‹€. μœ„μ—μ„œ μ€€ valuesλ₯Ό μ–Έμ œ μ• λ‹ˆλ©”μ΄μ…˜μ„ 쀄 지 타이밍과 κ΄€λ ¨λœ μš”μ†Œμž…λ‹ˆλ‹€. values의 λ°°μ—΄κ³Ό 같은 개수λ₯Ό κ°€μ§€κ±°λ‚˜ path ν”„λ‘œνΌν‹°μ˜ control point와 κ°œμˆ˜κ°€ κ°™μ•„μ•Ό μ˜λ„λŒ€λ‘œ λ™μž‘ν•©λ‹ˆλ‹€. 이 값은 calucationMode ν”„λ‘œνΌν‹°μ™€ 연관이 κΉŠμŠ΅λ‹ˆλ‹€. calucationModeκ°€ linear, cubic이라면, μœ„μ˜ κ·œμΉ™κ³Ό μΌμΉ˜ν•΄μ•Όν•©λ‹ˆλ‹€. (κ°œμˆ˜κ°€ 같아야함. 처음과 λ§ˆμ§€λ§‰ 값은 0κ³Ό 1) λ§Œμ•½ discrete이라면 κ°œμˆ˜λ³΄λ‹€ ν•˜λ‚˜κ°€ 더 λ§Žμ•„μ•Όν•©λ‹ˆλ‹€. cubicPaced λ˜λŠ” paced라면 이 ν”„λ‘œν”Όν„°λŠ” λ¬΄μ‹œλ©λ‹ˆλ‹€. 이 κ·œμΉ™μ„ 지킀지 μ•Šμ„ κ²½μš°μ—λ„ 이 ν”„λ‘œνΌν‹°λŠ” λ¬΄μ‹œλ©λ‹ˆλ‹€.

  • fillMode : Determines if the receiver’s presentation is frozen or removed once its active duration has completed. μ• λ‹ˆλ©”μ΄μ…˜μ˜ μ›€μ§μž„μ΄ 끝났을 λ•Œ, ν•΄λ‹Ή λ ˆμ΄μ–΄μ˜ ν”„λ ˆμ  ν…Œμ΄μ…˜, 즉 λ³΄μ—¬μ§€λŠ” 것은 λ©ˆμΆ”κ±°λ‚˜ ν˜Ήμ€ μ œκ±°λ˜κ±°λ‚˜ ν˜Ήμ€ λ‚¨μ•„μžˆκ±°λ‚˜λ₯Ό μ •ν•΄μ£ΌλŠ” ν”„λ‘œνΌν‹°μž…λ‹ˆλ‹€. backwards, forwards, removed, bothκ°€ μžˆλŠ”λ° 이것도 CAMediaTiming ν”„λ‘œν† μ½œκ³Ό 관련이 μžˆμŠ΅λ‹ˆλ‹€.

CAMediaTiming ν”„λ‘œν† μ½œμ€ μ• λ‹ˆλ©”μ΄μ…˜μ„ μ£ΌλŠ”λ° 정말 μ€‘μš”ν•œ μš”μ†Œκ΅¬λ‚˜

  • isRemovedOnCompletion : Determines if the animation is removed from the target layer’s animations upon completion. μ• λ‹ˆλ©”μ΄μ…˜μ˜ μ›€μ§μž„μ΄ 끝났을 λ•Œ ν•΄λ‹Ή μ• λ‹ˆλ©”μ΄μ…˜μ„ λ ˆμ΄μ–΄μ—μ„œ μ œκ±°ν•  것인지 말것인지에 λŒ€ν•œ μ—¬λΆ€μž…λ‹ˆλ‹€.

μ• λ‹ˆλ©”μ΄μ…˜μ΄ λλ‚˜κ³  ν•΄λ‹Ή μœ„μΉ˜λ₯Ό μœ μ§€ν•˜κ³  싢은 경우 μ• λ‹ˆλ©”μ΄μ…˜μ„ μ§€μš°μ§€μ•Šκ³ (isRemovedOnCompletion = false), fillModeλ₯Ό forwards둜 μ„€μ •ν•˜λ©΄ λœλ‹€.

  • isAdditive : Determines if the value specified by the animation is added to the current render tree value to produce the new render tree value. ν˜„μž¬ μœ„μΉ˜ κΈ°μ€€μ—μ„œ μ• λ‹ˆλ©”μ΄μ…˜ ν•  건지 μ•ˆν•  건지에 λŒ€ν•œ μ—¬λΆ€μž…λ‹ˆλ‹€. ν˜„μž¬ λ ˆμ΄μ–΄ λ Œλ” νŠΈλ¦¬μ— μƒˆλ‘œμš΄ λ Œλ”νŠΈλ¦¬ 값을 μƒμ„±ν•΄μ„œ μΆ”κ°€ν•©λ‹ˆλ‹€.

  • timeOffset : Specifies an additional time offset in active local time. ν˜„μž¬ μ• λ‹ˆλ©”μ΄μ…˜μ΄ μ‹€ν–‰λ˜κ³  μžˆλŠ” μ‹œκ°„μ— μΆ”κ°€ μ‹œκ°„μ„ λ”ν•˜λŠ” κ²ƒμž…λ‹ˆλ‹€. λ§Œμ•½ position을 0μ—μ„œ 10으둜 μ΄λ™μ‹œν‚€λŠ” μ• λ‹ˆλ©”μ΄μ…˜μ΄ μžˆλ‹€κ³  κ°€μ •ν•˜λ©΄ timeOffset이 4초라고 ν•˜λ©΄ 4 -> 10 -> 0 -> 4둜 μ΄λ™ν•©λ‹ˆλ‹€. 즉, 4μ—μ„œλΆ€ν„° μ• λ‹ˆλ©”μ΄μ…˜μ΄ μ‹œμž‘ν•©λ‹ˆλ‹€.

  • beginTime : Specifies the begin time of the receiver in relation to its parent object, if applicable.

    μ• λ‹ˆλ©”μ΄μ…˜ μ‹œμž‘ μ‹œκ°„

CAMediaTiming

μ ˆλŒ€μ μΈ μ‹œκ°„μ€ λ‹¨μœ„ "초"둜 κ³„μ‚°λ©λ‹ˆλ‹€. CACurrentMediaTime()λŠ” μ ˆλŒ€μ μΈ ν˜„μž¬ μ‹œκ°μ„ μ‰½κ²Œ κ°€μ Έμ˜¬ 수 μžˆμŠ΅λ‹ˆλ‹€. λΆ€λͺ¨μ˜ μ‹œκ°„μ—μ„œ 지역 μ‹œκ°„ (from parent time to local tiem)으둜 λ³€ν™˜ν•˜λŠ” 과정은 두 단계가 μžˆμŠ΅λ‹ˆλ‹€.

  1. "active local time"으둜 λ³€ν™˜
  2. "active local time"μ—μ„œ "basic local time"으둜 λ³€ν™˜

1번 λ‹¨κ³„μ—μ„œλŠ” ν˜„μž¬ 객체가 λΆ€λͺ¨ 객체의 μ‹œκ°„ μ†μ—μ„œ 어디에 λ‚˜νƒ€λ‚  지 포인트λ₯Ό μ•Œ 수 μžˆμŠ΅λ‹ˆλ‹€. 그리고 λ‘λ²ˆμ§Έ λ‹¨κ³„μ—μ„œλŠ” 타이밍 λͺ¨λΈμ€ ν•΄λ‹Ή μ• λ‹ˆλ©”μ΄μ…˜μ„ λ°˜λ³΅ν•  수 있고, λ’€λ‘œ 되돌릴 수 μžˆλ„λ‘ λ„μ™€μ€λ‹ˆλ‹€.

μ—¬κΈ°κΉŒμ§€ λ¬Έμ„œλ₯Ό 읽어보면 μ •ν™•ν•˜κ²Œ μ–΄λ–€ 건지 감이 μ˜€μ§€λŠ” μ•Šμ§€λ§Œ, λŒ€λž΅μ μœΌλ‘œ μ–΄λ–»κ²Œ μž‘λ™ν•  κ±΄μ§€λŠ” 감이 μ˜΅λ‹ˆλ‹€. Timing λ˜ν•œ λ·°κ³„μΈ΅μ²˜λŸΌ κ³„μΈ΅μœΌλ‘œ μ΄λ£¨μ–΄μ Έμžˆκ³  frameκ³Ό bound처럼 λΆ€λͺ¨μ™€μ˜ μƒλŒ€μ μΈ μ‹œκ°„κ³Ό λ‚˜μ˜ μ ˆλŒ€μ μΈ μ‹œκ°„μ΄ μžˆλ‹€κ³  이해할 수 μžˆμŠ΅λ‹ˆλ‹€. κ·Έλž˜μ„œ Customizing the Timing of an Animation λ¬Έμ„œλ₯Ό μ½μ–΄λ΄€μŠ΅λ‹ˆλ‹€.

μœ„μ—μ„œ μ΄ν•΄ν•œλŒ€λ‘œ, 각 λ ˆμ΄μ–΄λŠ” 각자의 둜컬 μ‹œκ°„μ„ 가지고 있고, 각각의 μ‹œκ°„ μ°¨μ΄λŠ” μœ μ €κ°€ 차이λ₯Ό λŠλΌμ§€ λͺ»ν•  μ •λ„λ‘œ μž‘μŠ΅λ‹ˆλ‹€. λ§Œμ•½, λ ˆμ΄μ–΄μ˜ 속도λ₯Ό λ³€κ²½ν•˜κ²Œ λœλ‹€λ©΄ μ• λ‹ˆλ©”μ΄μ…˜μ˜ duration도 변경될 것이고 λ‹€λ₯Έ λ ˆμ΄μ–΄μ™€ λ‹€λ₯΄κ²Œ μž‘λ™ν•˜κ² μ£ .

만일 속도=0이면? κ·Έλƒ₯ μ• λ‹ˆλ©”μ΄μ…˜μ΄ μž‘λ™μ•ˆν•  것 κ°™μŠ΅λ‹ˆλ‹€.

CAKeyframeAnimation λ¬Έμ„œμ—μ„œ beginTime ν”„λ‘œνΌν‹°μ— λŒ€ν•œ μ„€λͺ…을 μ½μ—ˆμ„ λ•ŒλŠ” 잘 이해가 λ˜μ§€ μ•Šμ•˜μ—ˆλŠ”λ°.. μ—¬κΈ°μ„œλ„ μ„€λͺ…이 λ‚˜μ™€μžˆμŠ΅λ‹ˆλ‹€. beginTime ν”„λ‘œνΌν‹°λŠ” μ• λ‹ˆλ©”μ΄μ…˜μ„ μ‹œμž‘ μ‹œκ°μ„ μ§€μ •ν•˜κΈ° μœ„ν•΄μ„œ μ‚¬μš©ν•©λ‹ˆλ‹€. μ• λ‹ˆλ©”μ΄μ…˜ 두가지λ₯Ό 연달아 μ΄μš©ν•˜κΈ° μœ„ν•΄μ„œλŠ” ν•œκ°œμ˜ μ• λ‹ˆλ©”μ΄μ…˜μ΄ λλ‚˜λŠ” μ‹œκ°„μ„ λ‹€λ₯Έ ν•˜λ‚˜μ˜ μ• λ‹ˆλ©”μ΄μ…˜μ˜ μ‹œμž‘μ‹œκ°„μœΌλ‘œ μ„€μ •ν•˜λ©΄ λ©λ‹ˆλ‹€. κ²°κ΅­ beginTime도 μ ˆλŒ€μ‹œκ°„μΈ 것 κ°™μŠ΅λ‹ˆλ‹€.