IOS5 Uiviewcontroller added the ability to manage Uiviewcontroller, just as easy as managing Subview. Here is a blog post that is very well presented. I used it in the project to facilitate the switch of view. The following code has the effect of a fade in/out.
- [Self TRANSITIONFROMVIEWCONTROLLER:_CURRENTVC toviewcontroller:newvc duration:0.5 options: Uiviewanimationoptiontransitioncrossdissolve animations:^{
- } completion:^ (BOOL finished) {
- }];
But how fast the call to trigger this method will appear: Unbalanced calls to begin/end appearance transitions for Uiviewcontroller
The reason is that the last animation was not over, and then started the new animation. This causes the page to not be successfully toggled, but a white, content-free page.
The workaround is to add a variable of type bool to check whether the animation is being made.
- if (transiting) {
- return ;
- }
- transiting = yes;
- [self transitionfromviewcontroller:_currentvc toviewcontroller:newvc duration:0.5 options:uiviewanimationoptiontransitioncrossdissolve animations:^{
-
- } completion:^ (bool finished) {
-
- transiting = NO;
- }];
This will not appear the bug that you just said.
The log unbalanced calls to Begin/end appearance transitions for Uiviewcontroller appears because of the uiviewcontroller of the container class (e.g., Uinavigationcontroller, Uitabbarcontroller) in the animation did not finish, and then start the new animation. The solution is to let the animation finish after the new animation.