我正在制作iOS UITabBar应用程序,我尝试使用动画转换。但是有些不对劲。当使用动画过渡更改视图时,我的应用程序显示黑色空白视图。
我的一些代码
类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
}
我会尝试在转换完成时添加此代码
}, completion: { finished in
transitionContext.completeTransition(true)
// add this line
UIApplication.sharedApplication().keyWindow!.addSubview(toView)
})
现在我的第二个视图显示正确,但我的标签栏消失了! 我正在尝试调试视图层次结构。看来我的标签栏并没有消失。但它带来了第二种观点。
如何解决这个问题?
PS。抱歉我的英语不好。
答案 0 :(得分:0)
如果仅在动画期间发生,请尝试禁用UITabBar半透明效果。在将我的设备更新到9.0之后,我发现了与自定义动画类似的行为,这最终成为我的根本问题。