我创建了自己的各种tabbarcontroller,但是我遇到动画问题。当我在选项卡上单击时为视图设置动画时,导航栏将完全变为黑色(应为红色),然后在动画完成后闪烁回红色。我的设置和代码如下。
(swift或objective-c中的答案很有用,因为转换很容易)
提前致谢!
红色:导航栏
蓝色:导航显示视图
灰色:标签栏
勃艮第:标签栏显示视图(这是正在过渡/动画的部分)
我使用以下代码在视图之间转换/动画。
//Handles selection of a tab bar item
func tabBar(tabBar: UITabBar, didSelectItem item: UITabBarItem!) {
//Get controller for transition
var selectedController = self.controllers[item.tag];
//Only transition for new view
if(self.childViewControllers[0] as UIViewController != selectedController!){
//Prepare for controller transition
selectedController!.viewWillAppear(false)
self.currViewController?.viewWillDisappear(false)
self.currViewController?.willMoveToParentViewController(nil)
//Set new controller with animation
selectedController!.view.frame = self.displayView.frame
if(transitionAnimated){
UIView.transitionFromView(self.displayView, toView: selectedController!.view, duration: self.animationDuration, options: self.animationOptions, completion: {finished in
self.setNewController(selectedController!)
self.animationCompletion(finished)
})
}
else{
self.displayView.removeFromSuperview()
self.view.addSubview(selectedController!.view)
setNewController(selectedController!);
}
}
else{
if(self.childViewControllers[0].isKindOfClass(UINavigationController)){
(self.childViewControllers[0] as UINavigationController).popToRootViewControllerAnimated(true)
}
}
}
我在UINavigationController上遇到了类似的问题并修复了它,试试看:
就在这一行之前:
UIView.transitionFromView(self.displayView, toView: selectedController!.view, duration: self.animationDuration, options: self.animationOptions, completion: {finished in
将选定的Controller.view添加到视图层次结构中(对不起Objc代码)qazxsw poi
让我知道它是否有效:)祝你好运!
[self.displayView.superview addSubview:selectedController.view];
这对我有用!!!