TabBarController转换在iOS中出现空白屏幕问题

时间:2016-12-29 12:01:35

标签: ios swift uitabbarcontroller uitabbar

在我的应用程序中使用Apple Objective-C linkSwift link的参考代码实现TabBarController转换。但是当我在两个标签之间快速切换时,我得到了空白屏幕,我在Stack Overflow中尝试了很多答案,但没有运气。

使用Swift

执行TabBarController Transitions时,请查看以下代码以供参考
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

2 个答案:

答案 0 :(得分:1)

似乎您已将UINavigationController用于第二个标签页。但不知何故,从USE [master] ALTER DATABASE [MyDatabase] ADD FILEGROUP [FG_MYBIGTABLE] secondViewController 的连接将丢失。请检查可能在您的方案中的故事板图像。the image of a storyboard

答案 1 :(得分:0)

我也获得了与空白屏幕相同的效果,并通过将当前视图作为初始视图控制器对其进行了修复。

检查是初始视图控制器 enter image description here