ios – 当我将它作为子视图(通过rootViewController属性)添加到UIWindow时,视图“跳跃”并进行翻转

我有两个简单的UIViewControllers,他们的视图是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,但它没有帮助.

更新:
当我从头开始隐藏statusBar(通过.info文件中的设置)时,不会进行视图调整.但仍然……我需要显示statusBar,我需要动画正常工作.

最佳答案 将rootViewController分配给窗口时,如果存在状态栏,则将
a new frame is assigned分配给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];
}
点赞