简体   繁体   中英

UITabBar show black screen when use animated transition. (swift)

I'm making iOS UITabBar application and I try to using animate transition. But there is something wrong. My app show black blank view when change view with animated transition.

My some code

class TransitionManager

...
func animateTransition(transitionContext: UIViewControllerContextTransitioning) {

    let container = transitionContext.containerView()
    let fromView = transitionContext.viewForKey(UITransitionContextFromViewKey)!
    let toView = transitionContext.viewForKey(UITransitionContextToViewKey)!

    let offScreenRight = CGAffineTransformMakeTranslation(container.frame.width, 0)
    let offScreenLeft = CGAffineTransformMakeTranslation(-container.frame.width, 0)

    toView.transform = offScreenRight

    container.addSubview(toView)
    container.addSubview(fromView)

    let duration = self.transitionDuration(transitionContext)

    UIView.animateWithDuration(duration, delay: 0.0, usingSpringWithDamping: 0.5, initialSpringVelocity: 0.8, options: nil, animations: {

        fromView.transform = offScreenLeft
        toView.transform = CGAffineTransformIdentity

        }, completion: { finished in
            transitionContext.completeTransition(true)
    })

}
...

UITabBarController

func tabBarController(tabBarController: UITabBarController, animationControllerForTransitionFromViewController fromVC: UIViewController, toViewController toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
    var animatedTransitioningObject = TransitionManager()
    return animatedTransitioningObject
}

I will try to add this code when transition complete

    }, completion: { finished in
        transitionContext.completeTransition(true)
        // add this line
        UIApplication.sharedApplication().keyWindow!.addSubview(toView)
})

Now my second view are show correctly, But my tabbar are disappear! I'm try to debug view hierarchy. It seem my tab bar isn't disappear. But It bring to back of second view.

How to fix this problem ?

ps. sorry for my bad english.

If it only happens during the animation, try disabling the UITabBar translucency. I found similar behaviour with custom animations after updating my device to 9.0 and that ended up being the root problem for me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM