Animation 如何在UIAbbarController中的不同UIViewController之间进行动画转换?

Animation 如何在UIAbbarController中的不同UIViewController之间进行动画转换?,animation,uitabbarcontroller,transition,Animation,Uitabbarcontroller,Transition,我有一个UITABBARC控制器,显示4个选项卡 我想在用户将屏幕滑动到切换选项卡时添加动画UIViewController转换。((无效)tabBarController:(UITabBarController*)tabBarController didSelectViewController:(UIViewController*)viewController方法仅适用于直接选择选项卡)。转换将采用easeinout样式 我尝试了以下代码,但没有工作。只有未来的UIViewController

我有一个UITABBARC控制器,显示4个选项卡

我想在用户将屏幕滑动到切换选项卡时添加动画UIViewController转换。((无效)tabBarController:(UITabBarController*)tabBarController didSelectViewController:(UIViewController*)viewController方法仅适用于直接选择选项卡)。转换将采用easeinout样式

我尝试了以下代码,但没有工作。只有未来的UIViewController移动,未来的UIViewController根本不显示。(我打印了所有UIViewController的帧数据,所有这4个UIViewController都是{0,0},{320480})

//获取视图。控制器索引已通过。
UIViewController*fromVC=[\u tabBarController.viewControllers对象索引:startIndex];
UIViewController*toVC=[\u tabbar controller.viewControllers objectAtIndex:to];
UIView*fromView=fromVC.view;
UIView*toView=toVC.view;
MWLog(@“从视图”为%@”,从视图);
int direct=startIndex-to;
//计算移动方向。
如果(直接<0){
CGRect OUTPRAME=fromView.frame;
outFrame.origin.x=-320;//expect fromView将移动到{-320,0}屏幕外。
MWLog(@“fromView的帧是%@”,NSStringFromCGRect(fromView.frame));
CGRect inFrame=toView.frame;
inFrame.origin.x=0;
MWLog(@“toView的帧为%@”,NSStringFromCGRect(toView.frame));
[UIView beginAnimations:@“moveView”上下文:nil];
[UIView设置动画曲线:UIViewAnimationCurveEaseInOut];
[UIView设置动画持续时间:0.5f];
toView.frame=inFrame;
fromView.frame=外帧;
[UIView委员会];
}否则
{
//反向移动。忽略。。。。
}

你能告诉我哪里不对劲,怎么做才对吗?提前谢谢

我终于找到了解决办法

使用CATTransition动画,键入push,根据方向键入left或right(通过计算tabbarcontroller的selectedIndex属性)。然后,将此动画添加到tabbarcontroller的容器视图中


可以通过枚举[tabbarcontroller子视图]数组中的所有UIView来获取此视图的引用。实际上,如果没有自定义UIView,tabbarcontroller包含两个子视图,一个是UITabBar,另一个是容器视图UITransitionView。在该视图中添加动画,可以为不同内容屏幕启用页面转换动画。

我终于找到了解决方案。使用CATTransition动画,键入push,根据方向键入left或right(通过计算tabbarcontroller的selectedIndex属性)。然后,将此动画添加到tabbarcontroller的容器视图中。可以通过枚举[tabbarcontroller子视图]数组中的所有UIView来获取此视图的引用。事实上,如果没有自定义UIView,tabbarcontroller包含两个子视图,一个是UITabBar,另一个是容器视图UITransitionView。我不明白您的解决方案的每个字。如果你能把你的例子改正过来,那就太好了。非常感谢。
// Get views. controllerIndex is passed. 
UIViewController *fromVC = [_tabBarController.viewControllers objectAtIndex:startIndex];
UIViewController *toVC = [_tabBarController.viewControllers objectAtIndex:to];

UIView *fromView = fromVC.view;
UIView *toView = toVC.view;

MWLog(@"from view is %@",fromView);

int direct = startIndex - to; 
// calculate move direction.
if (direct < 0) {

    CGRect outFrame = fromView.frame;
    outFrame.origin.x = -320; // expect fromView will move to {-320,0}, out of screen.
    MWLog(@"fromView's frame is %@", NSStringFromCGRect(fromView.frame));

    CGRect inFrame = toView.frame;
    inFrame.origin.x = 0;

    MWLog(@"toView's frame is %@", NSStringFromCGRect(toView.frame));

    [UIView beginAnimations:@"moveView" context:nil];

    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationDuration:0.5f];

    toView.frame = inFrame;
    fromView.frame = outFrame;
    [UIView commitAnimations];
}else
{
    // reverse moving. ignored....

}