模仿“正常”更改 UITabBar 的选定选项卡时查看转换

发布于 2024-09-12 16:29:16 字数 607 浏览 1 评论 0原文

由于太无聊而无法描述的原因,我正在以编程方式更改应用程序的选项卡栏以移动到不同的视图。不幸的是,这是即时的,我们希望在导航控制器上执行 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

初见 2024-09-19 16:29:16

让动画执行您想要的操作的最简单方法是首先将其从您希望它来自的位置(大概在屏幕之外)定位,然后然后启动< code>[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:)

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:

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];

Note that all this code is executed in an instant, so the setSelectedIndex will be set immediately as well: since there is no UIView 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:)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文