ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [CoreAnimation] Ch17. Presentation Controller & Orientation Animations
    Ray Wenderlich/Core Animation 2018. 10. 3. 23:17

    Section4. View Controller Transition Animators 

    지금까지 학습한 애니메이션을 기반으로 트랜지션 애니메이션을 구현할 수 있다. 

    Ch17. Presentation Controller & Orientation Animations 

    Intro 

    카메라앱, 주소록 앱 등에서 화면을 present할 때, 현재 화면 아래에서 새로운 화면이 올라오는 애니메이션 

    이를 커스텀하게 수정해보자. 

    Behind the scenes of custom transitions 

    UIKit에서는 delegate패턴을 사용하여 커스텀 트랜지션을 제공한다. 

    UIViewControllerTransitioningDelegate가 바로 그 델리게이트! 


    present가 발생할 때마다, UIKit은 animationController(forPresented:presenting:source:) 의 값이 있는지 확인한다. 

    nil이라면 디폴트 애니메이션을 수행한다. 

    animator가 커스텀 애니메이션을 수행하는 큰 과정은 

    1. duration을 확인하고, 

    2. animator의 animateTransition(using:)메소드를 실행한다. 

    animateTransition(using:)메소드 내부에서는 현재 viewController와 present될 viewController에 대한 레퍼런스를 가질 수 있다. 

    Implementing transition delegates 

    class PopAnimator: NSObject, UIViewControllerAnimatedTransitioning를 생성 

    ViewController에서 PopAnimator객체를 리턴하도록 UIViewControllerTransitioningDelegate프로토콜 구현 

    present되는 viewController의 transitionDelegate를 설정해준다. 

    Creating your transition animator 

    Setting your transitions context 

    animateTransition(using:)메소드에 전달되는 UIViewControllerContextTransitioning 타입객체. 

    트랜지션 작동 과정 

    - 트랜지션이 시작할 때, 현재 화면의 view가 container view에 붙는다. 

    - 그리고 새로운 viewController의 view가 애니메이션 되면서 container view에 붙는다. 

    Adding a fade transition 

    transitionContext의 아래 메소드를 활용하여 old&new 화면에 접근할 수 있다. 

    - view(forKey:) 

    - viewController(forKey:) 

    Adding a pop transition 

    트랜지션이 끝나면 transitionContext()를 호출하여 UIKit이 마무리할 수 있도록 하자. 

    convert(_:)메소드를 사용하여 선택한 이미지의 좌표를 구함 

    to에 nil을 전달하면 window에 해당하는 좌표계로 변환하는것 

    Adding a dismiss transition 

    present할 때 숨겨두었던 허브이미지뷰의 isHidden을 풀어주는 작업을 하자. 

    Device orientation transition 

    회전으로 발생하는 화면변경은 현재ViewController -> 현재ViewController로의 트랜지션이라고 생각하면 된다. 

    viewWillTransition(to size:coordinator:) 

    - iOS8에 소개됨 

    - 회전상태에 따라 배경화면의 alpha가 다르게 적용되도록 구현 


    UIKit이 회전 애니메이션을 실행하면서 coordinator의 animate(alongsideTransition:)에 전달된 애니메이션을 동시에 수행한다. 

    Challenge1 

    디테일화면을 present할 때, fade효과 주기. 

    alpha를 0에서 1로 주는 애니메이션으로 처리 

    Challenge2 

    메인화면의 이미지는 둥근 모서리 

    디테일화면의 모서리는 각진 모서리 

    이를 스무스하게 조정하는 애니메이션 

    corenerRadius로 처리 


    ———————————————————————————————————————— 

    animationController(forPresented:presenting:source:) 에서 presenting, source는 어떤 차이가?? 

    presenting과 항상 source가 일치하지는 않는다. 

    presentation context에 따라 다름 

    Ex) ChildViewController에서 present한다면 presenting과 source는 각각 어떤놈이 들어갈까? 

    - Defines Context 

    - Current Context 


    transitionDuration메소드의 역할은 무엇일까? 

    UIPageModelTransitionStyle

Designed by Tistory.