模仿“正常”更改 UITabBar 的选定选项卡时查看转换
由于太无聊而无法描述的原因,我正在以编程方式更改应用程序的选项卡栏以移动到不同的视图。不幸的是,这是即时的,我们希望在导航控制器上执行 pushViewController
时获得正常的快速加载效果。
我对在 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];
这做了一个动画,导航栏神秘地从上面出现,不完全是我想要的:)
For reasons too boring to describe, I am programatically changing my application's tab bar to move to a different view. Unfortunately that is instant and we would like the normal snazy load effect you get when you would do a pushViewController
on a navigation controller.
I am very inexperienced with using animations in objc c, I attempted to use some code I found here for mine:
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];
This does an animation of sorts, the nav bar mysteriously appears from above, not quite what I wanted :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
让动画执行您想要的操作的最简单方法是首先将其从您希望它来自的位置(大概在屏幕之外)定位,然后然后启动< code>[UIView ...] 块,您可以在其中设置新框架。所以总体轮廓是:
请注意,所有这些代码都是在瞬间执行的,因此
setSelectedIndex
也将立即设置:因为那里没有涉及UIView
,所以它不是动画的。要触发动画之外的内容,请查看其他问题。 (简而言之:使用animationDelegate,或performSelector:afterDelay:)The easiest way to get your animation to do what you want, is to first position it from the place you want it to come from (which is outside of the screen, presumably), and then start the
[UIView ...]
block, in which you set the new frame. So the general outline is:Note that all this code is executed in an instant, so the
setSelectedIndex
will be set immediately as well: since there is noUIView
involved there, it is not animated. To fire something past the animation, have a look at other questions. (in short: use the animationDelegate, or performSelector:afterDelay:)