【问题标题】:UIView not initialised properly before rotationUIView 在旋转前未正确初始化
【发布时间】:2011-03-23 16:59:22
【问题描述】:

我使用的代码与下面非常相似:

- (void)flipToViewController:(UIViewController*)targetViewController
              transition:(UIViewAnimationTransition)transition

{ 如果(目标视图控制器) { [[[self activeViewController] view] setUserInteractionEnabled:NO];

  // force the view to be instantiated (loadView/layoutSubviews)
  [[targetViewController view] setHidden:NO];

  [UIView beginAnimations:nil context:NULL];
  [UIView setAnimationDuration:0.8f];
  [UIView setAnimationTransition:transition forView:self.view cache:YES];

  [targetViewController viewWillAppear:YES];
  [[self activeViewController] viewWillDisappear:YES];

  [[[self activeViewController] view] removeFromSuperview];

  [[self view] addSubview:[targetViewController view]];

  [[self activeViewController] viewDidDisappear:YES];
  [targetViewController viewDidAppear:YES];

  [[targetViewController view] setUserInteractionEnabled:YES];

  [UIView commitAnimations];

  [self setActiveViewController:targetViewController];
  }

}

我正在使用翻转过渡,但是,当我的 targetViewController 翻转到视图中时,视图未正确初始化。 UISegmentedControl 看起来很奇怪,并且一个子视图位于错误的位置。

只有在动画结束后,所有的东西才会进入正确的位置。

我在 viewWillAppear(不是 viewDidAppear)中进行了所有子视图设置,所以我不明白为什么它没有及时初始化。

有什么建议吗?

我还注意到(在调试之后) viewWillAppear 在 vi​​ewDidLoad 方法之前被调用?为什么要这样做?

【问题讨论】:

    标签: iphone animation uiviewcontroller transition flip


    【解决方案1】:

    移动以下行:

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.8f];
    [UIView setAnimationTransition:transition forView:self.view cache:YES];
    

    .. 就在这一行的下方:

    [[self view] addSubview:[targetViewController view]];
    

    显然 addSubView/insertSubView 不能在动画中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-04-21
      • 2012-06-17
      • 2022-01-22
      • 2014-10-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多