UIView 动画后顶部有间隙

发布于 2024-11-16 02:55:50 字数 1109 浏览 4 评论 0原文

我有一个 tabbarview 应用程序,其中一个选项卡中有一个按钮。当按下该按钮时,会发生一些事情,用户将切换到另一个选项卡。

我在该按钮中制作了一个动画:

UIView * fromView = self.tabBarController.selectedViewController.view;
UIView * toView = [[self.tabBarController.viewControllers objectAtIndex:0] view];
[UIView transitionFromView:fromView 
                    toView:toView 
                  duration:0.6 
                   options:(UIViewAnimationOptionTransitionCurlDown)
                completion:^(BOOL finished) {
                    if (finished) {
                        self.tabBarController.selectedIndex = 0;
                    }
                }];

这是我从 获得的在这里。然而问题是,动画之后,屏幕顶部似乎有一个与状态栏一样高的间隙。有谁知道这是什么原因造成的?当动画完成时(当我们执行 self.tabBarController.selectedIndex = 0

顺便说一句,如果我将动画交换为其他内容甚至没有动画,问题仍然存在。

附加信息,这是帧详细信息:

from frame: x:0.000000, y:0.000000, w:320.000000, h:411.000000
to frame: x:0.000000, y:0.000000, w:320.000000, h:431.000000

I have a tabbarview application that has a button in one of the tabs. When Pressing that button, something will happen, and the user will be switched to another tab.

I made an animation in that button:

UIView * fromView = self.tabBarController.selectedViewController.view;
UIView * toView = [[self.tabBarController.viewControllers objectAtIndex:0] view];
[UIView transitionFromView:fromView 
                    toView:toView 
                  duration:0.6 
                   options:(UIViewAnimationOptionTransitionCurlDown)
                completion:^(BOOL finished) {
                    if (finished) {
                        self.tabBarController.selectedIndex = 0;
                    }
                }];

Which I got from here. However the problem is that after animating, I seem to have a gap on the top of the screen that is about as high as the status bar. Does anyone know what's causing this? This gap quickly closes when the animation finishes (which is when we do self.tabBarController.selectedIndex = 0

Sorry I had to hide some details

By the way, the problem still persist if I swap the animation to something else or even without animation.

Additional info, here's the frame details:

from frame: x:0.000000, y:0.000000, w:320.000000, h:411.000000
to frame: x:0.000000, y:0.000000, w:320.000000, h:431.000000

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

瑕疵 2024-11-23 02:55:50

标签栏控制器的区域还覆盖状态栏下方的区域。因此它自己的客户端视图的 origin.y 为 20。

因此,您需要在调用转换之前正确设置传入视图框架。

The tab bar controller's area also covers the area underneath the status bar. So it's own client view has origin.y of 20.

Thus you need to set the incoming view frame correctly before invoking the transition.

伴我老 2024-11-23 02:55:50

我找到了一种非常老套的方法:

CGRect to = fromView.superview.frame;
to.origin.y -= 20;
fromView.superview.frame = to;

任何可以向我解释为什么我必须这样做以及更优雅的方法的人都会得到答案。

I've found a very hacky way to do it:

CGRect to = fromView.superview.frame;
to.origin.y -= 20;
fromView.superview.frame = to;

Anyone that can explain to me why I had to do this and a more elegant way to do this will get the answer accepted.

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