gpt4 book ai didi

ios - 当我将它作为 subview (通过 rootViewController 属性)添加到 UIWindow 并进行翻转时, View 为 “jumping”

转载 作者:可可西里 更新时间:2023-11-01 05:58:57 37 4
gpt4 key购买 nike

我有两个简单的 UIViewController,它们的 View 是 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];
}

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

更新:当我从一开始就隐藏 statusBar(通过 .info 文件中的设置)时,不会进行 View 调整。但是仍然...我需要显示 statusBar 并且我需要该动画正常工作。

最佳答案

当一个 rootViewController 被分配给一个窗口时,a new frame is assigned如果存在状态栏,则显示到 rootViewController 的 View 。这样 rootViewController 的 View 不会隐藏在状态栏下。

由于您是在动画 block 内设置窗口的 rootViewController,因此新的帧分配也会被动画化。

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

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

关于ios - 当我将它作为 subview (通过 rootViewController 属性)添加到 UIWindow 并进行翻转时, View 为 “jumping”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5830670/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com