更改TabBar选定选项卡时模仿“正常”视图转换

时间:2010-08-04 16:25:52

标签: objective-c animation uitabbarcontroller

由于无法描述的原因,我正在以编程方式更改应用程序的标签栏以移至不同的视图。不幸的是,这是即时的,我们希望您在导航控制器上执行pushViewController时获得正常的snazy加载效果。

我对在objc中使用动画非常缺乏经验,我试图使用我在这里找到的一些代码:

CGContextRef context = UIGraphicsGetCurrentContext();
[UIView beginAnimations:nil context:context];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:[self view] cache:YES];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:2.0];
[[[self nav] tabBarController] setSelectedIndex:2];
[UIView commitAnimations];

这是一个各种各样的动画,导航栏从上面神秘地出现,不是我想要的那样:)

1 个答案:

答案 0 :(得分:0)

让你的动画做你想做的最简单的方法是首先将它从你想要的地方放置(大概是在屏幕之外),然后然后启动[UIView ...]块,在其中设置新帧。总的轮廓是:

CGRect newframe = theView.frame;
newframe.origin.x = 320.0f;
theView.frame = newframe;

[UIView beginAnimations:nil context:nil];
          // btw the context is just your context for animation delegate callbacks!
newframe.origin.x = 0.0f;
theView.frame = newframe;
[UIView commitAnimations];

请注意,所有这些代码都会立即执行,因此setSelectedIndex也会立即设置:因为那里没有UIView,所以它不是动画。要通过动画点击某些内容,请查看其他问题。 (简而言之:使用animationDelegate或performSelector:afterDelay:)