2016-12-29 2 views
0

In meiner Anwendung implementiert TabBarController Transitionen mit Referenz-Code von Apple Objective-C link Und Swift link. Aber wenn ich schnell zwischen zwei Tabs umschalte bekomme ich einen leeren Bildschirm, habe ich viele Antworten in Stack Overflow versucht, aber kein Glück.TabBarController Übergänge immer leeren Bildschirm Problem in iOS

Bitte überprüfen Referenz Code unten, während TabBarController Transitions Swift

mit tun
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) 
    }) 
} 

unter dem Bildschirm enter image description here

+0

Haben Sie nur schwarzen Bildschirm? –

+0

Screenshot hinzugefügt, bitte einmal prüfen. –

+1

@AnjaneyuluBattula Ist Ihr Storyboard-Muster wie folgt: Tab-Leiste Controller -> Navigation Controller -> View Controller? – Amanpreet

Antwort

1

Schuss ist es scheint, wie Sie UINavigationController für Ihren zweiten Registerkarte genommen haben. Aber irgendwie ist Ihre Verbindung von UINavigationController zu Ihrem secondViewController verloren. Überprüfen Sie das Bild eines Storyboards, das in Ihrem Szenario enthalten sein kann. the image of a storyboard

+0

Eigentlich ist das nicht das Szenario. Wenn möglich, können Sie bitte die Beispielcodes überprüfen, die ich erwähnt habe. –

Verwandte Themen