UITabBar shows black screen when using animated transition. (Fast)
I am making an iOS UITabBar app and I am trying to use an animated transition. But something is wrong. My app shows a black blank view when changing view with an animated transition.
My code
TransitionManager class
...
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 the transition is complete
}, completion: { finished in
transitionContext.completeTransition(true)
// add this line
UIApplication.sharedApplication().keyWindow!.addSubview(toView)
})
Now my second view displays correctly, but my panel disappears! I am trying to debug a view hierarchy. My tab bar doesn't seem to disappear. But this brings back a second look.
How to solve this problem?
ps. sorry for my bad english.
+3
source to share