2019년 9월 16일 월요일

탭 전환시 애니메이션 효과 주기


방법 
  • TabBarControllerDelegate Method 구현 
내용
func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
        
        let fromView = tabBarController.selectedViewController?.view
        let toView = viewController.view
        
        if fromView == toView {
            if isTabActivated {
                initWebView()
            }
            return false
        }
        
        UIView.transition(from: fromView!, to: toView!, duration: 0.3, options: UIView.AnimationOptions.transitionCrossDissolve) { (_) in
        }
        
        return true
    }

이슈 및 추가확인 사항 
  • 해당 방법으로는 AnimationOption의 항목으로 애니메이션 효과를 줄 수 있었다.
  • shouldSelect 와 didSelect 항목이 같이 구현되면 충돌이 있는 것 같다. 작동하던 코드 하나가 더이상 작동하지 않아 shouldSelect로 옮김 
API Reference 
  • func tabBarController(UITabBarController, shouldSelect: UIViewController) -> Bool
  • UIView.AnimationOptions 

참고: 1, 2, 3.