简体   繁体   English

如何添加过渡以在选项卡视图控制器之间进行切换

[英]How to add transition for switching between tabbar viewcontrollers

I added UITabBarViewController to my app and added five ViewControllers . 我将UITabBarViewController添加到我的应用程序中,并添加了五个ViewControllers Each VC to one of the TabBarItems . 每个VCTabBarItems And all of this is working good. 所有这些都运行良好。 But for the third view is made for user to input some data, so I want it to be presented as temporary VC . 但是由于第三个view是供用户输入一些数据的,因此我希望将其显示为临时VC The usual transition for temporary VC is crossdisolve. 临时VC的通常过渡是交叉溶解。 This brings the VC up from the bottom. 这使VC从底部开始。

So my question is how can I make this animation for transition between TabBarItems . 所以我的问题是如何制作此动画以在TabBarItems之间进行过渡

I use this function which takes in the index of the destination view. 我使用此函数接收目标视图的索引。 I would add this function as part of the parent view controller to be called by the sub-view controllers. 我将此功能添加为要由子视图控制器调用的父视图控制器的一部分。 That's up to you. 随你(由你决定。

-(void) animateTabBarTransition:(NSInteger) destinationTabIdx{
   UIView * fromView = self.tabBarController.selectedViewController.view;
   UIView * toView = [[self.tabBarController.viewControllers objectAtIndex:destinationTabIdx] view];

  [UIView transitionFromView:fromView toView:toView duration:0.8
    options:(destinationTabIdx > self.tabBarController.selectedIndex ? UIViewAnimationOptionTransitionFlipFromLeft: UIViewAnimationOptionTransitionFlipFromRight)
            completion:^(BOOL finished) {
                if (finished) {
                    self.tabBarController.selectedIndex = destinationTabIdx;
                }
}];

} }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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