2016-12-29 5 views
0

В моем приложении реализованы переходы TabBarController с использованием кода ссылки Apple Objective-C link И Swift link. Но когда я переключаюсь между двумя вкладками несколько раз, я получаю пустой экран, я попробовал много ответов в Stack Overflow, но не повезло.Переходы TabBarController, получающие пустой экран в iOS

Пожалуйста, проверьте ниже код для справки при выполнении TabBarController Переходов с помощью Swift

func animateTransition(using transitionContext: UIViewControllerContextTransitioning) { 
    let fromViewController = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.from)! 
    let toViewController = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.to)! 

    let containerView = transitionContext.containerView 
    let fromView: UIView 
    let toView: UIView 

    // In iOS 8, the viewForKey: method was introduced to get views that the 
    // animator manipulates. This method should be preferred over accessing 
    // the view of the fromViewController/toViewController directly. 
    if #available(iOS 8.0, *) { 
     fromView = transitionContext.view(forKey: UITransitionContextViewKey.from)! 
     toView = transitionContext.view(forKey: UITransitionContextViewKey.to)! 
    } else { 
     fromView = fromViewController.view 
     toView = toViewController.view 
    } 

    let fromFrame = transitionContext.initialFrame(for: fromViewController) 
    let toFrame = transitionContext.finalFrame(for: toViewController) 

    // Based on the configured targetEdge, derive a normalized vector that will 
    // be used to offset the frame of the view controllers. 
    var offset: CGVector 
    if self.targetEdge == UIRectEdge.left { 
     offset = CGVector(dx: -1.0, dy: 0.0) 
    } else if self.targetEdge == .right { 
     offset = CGVector(dx: 1.0, dy: 0.0) 
    } else { 
     fatalError("targetEdge must be one of UIRectEdgeLeft, or UIRectEdgeRight.") 
    } 

    // The toView starts off-screen and slides in as the fromView slides out. 
    fromView.frame = fromFrame 
    toView.frame = toFrame.offsetBy(dx: toFrame.size.width * offset.dx * -1, 
     dy: toFrame.size.height * offset.dy * -1) 

    // We are responsible for adding the incoming view to the containerView. 
    containerView.addSubview(toView) 

    let transitionDuration = self.transitionDuration(using: transitionContext) 

    UIView.animate(withDuration: transitionDuration, animations: { 
     fromView.frame = fromFrame.offsetBy(dx: fromFrame.size.width * offset.dx, 
      dy: fromFrame.size.height * offset.dy) 
     toView.frame = toFrame 

     }, completion: {finshed in 
      let wasCancelled = transitionContext.transitionWasCancelled 
      // When we complete, tell the transition context 
      // passing along the BOOL that indicates whether the transition 
      // finished or not. 
      transitionContext.containerView.addSubview(toView) 
      transitionContext.completeTransition(!wasCancelled) 
    }) 
} 

Ниже снимок экрана enter image description here

+0

У вас есть только черный экран? –

+0

Добавлен скриншот, пожалуйста, проверьте один раз. –

+1

@AnjaneyuluBattula Является ли ваш шаблон раскадровки похожим: панель управления панелью -> контроллер навигации -> просмотр контроллера? – Amanpreet

ответ

1

Похоже, что вы приняли UINavigationController для второй вкладке. Но как-то ваше соединение от UINavigationController к вашему secondViewController потеряно. Проверьте изображение раскадровки, которое может быть в вашем сценарии. the image of a storyboard

+0

На самом деле это не сценарий. Если возможно, вы можете проверить коды образцов, о которых я упоминал. –