UIView not initialised properly before rotation
Im using code very similar to below:
- (void)flipToViewController:(UIViewController*)targetViewController
transition:(UIViewAnimationTransition)transition
{ if( targetViewController ) { [[[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];
[[[se开发者_如何学Pythonlf activeViewController] view] removeFromSuperview];
[[self view] addSubview:[targetViewController view]];
[[self activeViewController] viewDidDisappear:YES];
[targetViewController viewDidAppear:YES];
[[targetViewController view] setUserInteractionEnabled:YES];
[UIView commitAnimations];
[self setActiveViewController:targetViewController];
}
}
Im using a flip transition, However, when my targetViewController flips into view, the view isn't initialised properly. The UISegmentedControl looks weird and one subview is in the wrong position.
Only after the animation finishes does everything settle into the correct location.
I do all my subview setup in viewWillAppear (not viewDidAppear), so i dont understand why it isn't initialised in time.
Any suggestions?
I also notice (after debugging) that viewWillAppear is called before the viewDidLoad method? Why would it do this?
Move the following lines:
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.8f];
[UIView setAnimationTransition:transition forView:self.view cache:YES];
.. just below this line:
[[self view] addSubview:[targetViewController view]];
Apparently the addSubView/insertSubView must not be within the animation.
精彩评论