Iphone UIView在旋转前未正确初始化
我使用的代码与下面非常相似:Iphone UIView在旋转前未正确初始化,iphone,animation,uiviewcontroller,transition,flip,Iphone,Animation,Uiviewcontroller,Transition,Flip,我使用的代码与下面非常相似: - (void)flipToViewController:(UIViewController*)targetViewController transition:(UIViewAnimationTransition)transition { if(targetViewController) { [[[self-activeViewController]视图]setUserInteractionEnabled:否] // force t
- (void)flipToViewController:(UIViewController*)targetViewController
transition:(UIViewAnimationTransition)transition
{
if(targetViewController)
{
[[[self-activeViewController]视图]setUserInteractionEnabled:否]
// 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看起来很奇怪,一个子视图位置错误
只有在动画完成后,所有内容才会进入正确的位置
我在ViewWillDisplay(而不是ViewDidDisplay)中执行所有子视图设置,因此我不明白为什么它没有及时初始化
有什么建议吗
我还注意到(调试后)在viewDidLoad方法之前调用了ViewWillDisplay?为什么要这样做?移动以下行:
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.8f];
[UIView setAnimationTransition:transition forView:self.view cache:YES];
…就在这条线下面:
[[self view] addSubview:[targetViewController view]];
显然,addSubView/insertSubView不能在动画中