2010-08-04 22 views
1

由于无法描述的原因,我正在编程上将我的应用程序标签栏更改为不同的视图。不幸的是,这是瞬间的,我们希望当你在导航控制器上执行pushViewController时,你会得到正常的负载效应。在更改UITabBar的选定标签时模仿“正常”视图转换

我非常缺乏经验,在objc c中使用动画,我尝试使用一些代码,我发现这里的矿:

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

我知道这是旧的,但对于它的价值,从iOS 4.0开始,您可以使用新的UIView转换函数。我做了一些非常相似的事情,但是在完成的动画模块中调用了setSelectedIndex:这个模块效果很好。 – slycrel 2010-11-30 08:15:16

回答

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 :)