2017-03-13 1 views
0

UIViewControllerAnimatedTransitioning을 사용하여 뷰 컨트롤러에 사용자 정의 애니메이션이있는 TabBarController가 있습니다.프리젠 테이션 애니메이션 후 뷰 컨트롤러가 사라짐

애니메이션은 문제없이 정상적으로 실행되지만 animationController(forPresented) 함수를 실행하면 Presenting view controller이 사라집니다.

같은 문제가있는 사람들과 관련하여 질문을 찾았지만 내 문제는 해결되지 않았습니다.

iOS에 버그가 있으며 스택에 '사라진'보기 컨트롤러가 있어야한다는 것을 읽었지 만 UIApplication.shared.keyWindow?.addSubview(presentingView)과 함께 추가하면보기가 presentedView 상단에 추가되며 잘 모릅니다. 그것을 다시 추가하면 그래픽 버그 일 수 있고 뷰가 여전히 컨테이너의 일부이기 때문에 스택에 또 하나를 추가합니다. 애니메이션 자체가 단지 주변을 확장, 내가 뭘 단지 테스트 것을

// Global var 
var transition = Animator() 

// Present a VC modally using tab bar 
func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool { 
    if viewController is NewPostVC { 
     if let newVC = tabBarController.storyboard?.instantiateViewController(withIdentifier: "newPostVC") as? NewPostVC { 
      newVC.transitioningDelegate = self 
      newVC.interactor = interactor // new 
      tabBarController.present(newVC, animated: true) 
      return false 
     } 
    } 
    return true 
} 

// Handles the presenting animation 
func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? { 
    transition.transitioningMode = .Present 
    return transition 
} 


// Handles the dismissing animation 
func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? { 
    transition.transitioningMode = .Dismiss 
    return transition 
} 


// interaction controller, only for dismissing the view; 
func interactionControllerForDismissal(using animator: UIViewControllerAnimatedTransitioning) -> UIViewControllerInteractiveTransitioning? { 
    return interactor.hasStarted ? interactor : nil 
} 


//***************************** 
/// On the Animator class: 
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) { 
     let containerView = transitionContext.containerView 

     // Animates to present 
     if transitioningMode == .Present { 

      // Get views 
      guard 
       let presentedView = transitionContext.view(forKey: UITransitionContextViewKey.to), 
       let presentingView = transitionContext.view(forKey: UITransitionContextViewKey.from) 
       else { 
        print("returning") 
        return 
      } 

      // Add the presenting view controller to the container view 
      containerView.addSubview(presentingView) 

      // Add the presented view controller to the container view 
      containerView.addSubview(presentedView) 

      // Animate 
      UIView.animate(withDuration: presentDuration, animations: { 

       presentingView.transform = CGAffineTransform.identity.scaledBy(x: 0.85, y: 0.85); 
       presentingView.layer.cornerRadius = 7.0 
       presentingView.layer.masksToBounds = true 

       presentedView.transform = CGAffineTransform.identity.scaledBy(x: 0.6, y: 0.6); 
       presentedView.layer.masksToBounds = true 

      }, completion: { _ in 
       // On completion, complete the transition 
       transitionContext.completeTransition(true) 

       //UIApplication.shared.keyWindow?.addSubview(presentingView) 
      }) 


     } 
     // Animates to dismiss 
     else { 
      // TODO: - Implement reverse animation 
     } 
    } 

참고 :

는 여기에 몇 가지 코드입니다.

Thx.

+0

내가 모르는 한 가지는 presentingView와 displayedView를 모두 Container에 추가해야한다는 점입니다. 또는 presentView 만 추가해야합니다. 이 글에서 정말 실망했습니다. –

+0

Apple 설명서에 : 프레젠테이션을 위해 "to"뷰를 컨테이너 뷰 계층 구조에 추가하십시오. 해고의 경우 컨테이너보기 계층 구조에서 "시작"보기를 제거하십시오. 나는 'to'뷰를 스택에 추가하기 만하면된다고 생각한다. –

답변

0

Apple의 관련 설명서 here을 읽은 후 presentingViewController가 화면에서 사라지는 버그가 아니라는 것을 알게되었습니다. 이는 API가 작동하는 방식입니다.

전송 애니메이션을 사용하는 사람은 누구나 문서를 읽고 업데이트되었으며 재미 있고 확실한 설명을 찾을 수 있습니다.

관련 문제