gpt4 book ai didi

iphone - iOS 中 View Controller 和旋转之间的转换

转载 作者:可可西里 更新时间:2023-11-01 17:09:41 25 4
gpt4 key购买 nike

考虑一个带有两个 subview Controller (A 和 B)的容器 View Controller ,它们都使用 addChildViewController: 添加。然后:

  1. A.view添加到容器 View
  2. B 通过执行从 A 到 B 的 transitionFromViewController 显示。B 收到 viewWillLayoutSubviews,一切都很好。
  3. 设备在显示 B 的同时旋转。只有 B 接收到旋转调用(willRotateToInterfaceOrientation: 等)。
  4. 通过执行从 B 到 A 的 transitionFromViewController 显示 A。A 没有收到 viewWillLayoutSubviews,因此布局被破坏。

这是预期的行为吗?如果没有,我可能做错了什么?如果是,如何在显示B的同时通知A旋转变化?

最佳答案

一旦调用 addChildViewController:,您现在就是 View Controller 容器实现者。这意味着您确实需要做比标准演示调用(如 presentViewController..)多一点的工作。这包括处理您作为子项添加的 Controller 的 View 框架,正如您的问题表明您可能已经预料到的那样。

例如,要实现一个 super 基本的示例容器,它只显示每个 child 全屏,您可以这样做。

-(void)swapChildVCFrom:(UIViewController *)from to:(UIViewController *)to{
[self addChildViewController:to];
[from willMoveToParentViewController:nil];

// Adjust the new child view controller's view's frame
// For example here just set it to fill the parent view
to.view.frame = self.view.bounds;

[self transitionFromViewController:from
toViewController:to
duration:1.0
options:UIViewAnimationOptionTransitionFlipFromLeft
animations:nil
completion:^(BOOL b){
[to didMoveToParentViewController:self];
[from.view removeFromSuperview];
[from removeFromParentViewController];
}];
}

关于iphone - iOS 中 View Controller 和旋转之间的转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13433060/

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