景色是“跳跃”的。当我将它添加到 UIWindow 作为子视图(通过 rootViewController 属性)并进行翻转时

发布于 2024-11-04 02:14:33 字数 942 浏览 3 评论 0原文

我有两个简单的 UIViewController,它们的视图为 320 x 460,带有状态栏。我在 AppDelegate 中

self.window.rootViewController = [[[SimpleController alloc] init] autorelease];

[self.window makeKeyAndVisible];

的 SimpleController 中做了一个按钮,该按钮执行

- (IBAction) switchToVerySimpleController
{
  [UIView transitionWithView: [[UIApplication sharedApplication] keyWindow]
                    duration: 0.5
                     options: UIViewAnimationOptionTransitionFlipFromLeft
                  animations:^{ [[UIApplication sharedApplication] keyWindow].rootViewController = [[[VerySimpleController alloc] init] autorelease]; }
                  completion: NULL];
}

新视图(VerySimpleController.view)填充蓝色。动画结束后,新视图会在底部显示一个微小的白色条纹(状态栏大小),然后向下跳到位。为什么会发生这种情况以及如何避免这种情况?我想这应该归咎于状态栏,我尝试在 IB 中为两个视图设置 statusBar = Unspecified,但这没有帮助。

更新: 当我从一开始就隐藏状态栏(通过 .info 文件中的设置)时,不会发生视图调整。但仍然...我需要显示状态栏并且我需要该动画正常工作。

I have two simple UIViewControllers, their views are 320 x 460 with status bars. I do in AppDelegate

self.window.rootViewController = [[[SimpleController alloc] init] autorelease];

[self.window makeKeyAndVisible];

In SimpleController I have a button that does

- (IBAction) switchToVerySimpleController
{
  [UIView transitionWithView: [[UIApplication sharedApplication] keyWindow]
                    duration: 0.5
                     options: UIViewAnimationOptionTransitionFlipFromLeft
                  animations:^{ [[UIApplication sharedApplication] keyWindow].rootViewController = [[[VerySimpleController alloc] init] autorelease]; }
                  completion: NULL];
}

The new view (VerySimpleController.view) is filled with a blue color. After animation new view is shown with a tiny white stripe (with the size of a status bar) at the bottom and then it jumps down into place. Why is it happening and how to avoid that? I suppose its status bar to blame, and I tried to set statusBar = Unspecified in IB for both views, but it doesn't help.

UPDATE:
When I hide statusBar (thru setting in .info file) from the start, no view adjustment occurs. But still... I need to show statusBar and I need that animation working properly.

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

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

发布评论

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

评论(2

野味少女 2024-11-11 02:14:33

当 rootViewController 分配给窗口时, a如果存在状态栏,新框架将被分配到 rootViewController 的视图。这样 rootViewController 的
视图不会隐藏在状态栏下方。

由于您在动画块内设置窗口的 rootViewController,因此新的帧分配也会进行动画处理。

为了不显示跳转,您可以在动画之前设置 rootViewController 视图的框架,如下所示:

- (IBAction) switchToVerySimpleController
{
    CGRect statusBarFrame = [[UIApplication sharedApplication] statusBarFrame];

    VerySimpleController *vsc = [[[VerySimpleController alloc] init] autorelease];

    vsc.view.frame = CGRectMake(vsc.frame.origin.x,
                     statusBarFrame.size.height,
                     vsc.frame.size.width,
                     vsc.frame.size.height);

    [UIView transitionWithView: [[UIApplication sharedApplication] keyWindow]
                      duration: 0.5
                       options: UIViewAnimationOptionTransitionFlipFromLeft
                    animations:^{ [[UIApplication sharedApplication] keyWindow].rootViewController = vsc }
                    completion: NULL];
}

When a rootViewController is assigned to a window, a new frame is assigned to the rootViewController's view if a status bar is present. This is so that the rootViewController's
view won't be hidden under the status bar.

Since you're setting the window's rootViewController inside the animation block, the new frame assignment gets animated as well.

To not show the jump you might set the frame of the rootViewController's view before the animation with something like this:

- (IBAction) switchToVerySimpleController
{
    CGRect statusBarFrame = [[UIApplication sharedApplication] statusBarFrame];

    VerySimpleController *vsc = [[[VerySimpleController alloc] init] autorelease];

    vsc.view.frame = CGRectMake(vsc.frame.origin.x,
                     statusBarFrame.size.height,
                     vsc.frame.size.width,
                     vsc.frame.size.height);

    [UIView transitionWithView: [[UIApplication sharedApplication] keyWindow]
                      duration: 0.5
                       options: UIViewAnimationOptionTransitionFlipFromLeft
                    animations:^{ [[UIApplication sharedApplication] keyWindow].rootViewController = vsc }
                    completion: NULL];
}
紙鸢 2024-11-11 02:14:33

看来这个问题有时仍然会发生,这可能是一个错误。

为了避免这种“跳转”,请将此代码添加到需要显示的视图控制器的 viewWillAppear 方法中:

swift

navigationController?.navigationBar.layer.removeAllAnimations()

Objective-c

[self.navigationController.navigationBar.layer removeAllAnimations];

现在,转换将在没有“跳转”的情况下完成。

It seems that this issue still sometimes happen and it's probably a bug.

To avoid this 'jump' add this code to the viewWillAppear method of the view controller which needs to be shown:

swift

navigationController?.navigationBar.layer.removeAllAnimations()

objective-c

[self.navigationController.navigationBar.layer removeAllAnimations];

The transition will now finish without the 'jump'.

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