Zuikyo / ZIKRouter

Interface-oriented router for discovering modules, and injecting dependencies with protocol in Objective-C and Swift.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ZIKViewRouter Error

zx2696108 opened this issue · comments

router's action (ZIKRouteActionPerformRoute) catch error: (Error Domain=kZIKViewRouteErrorDomain Code=4 "Unbalanced calls to begin/end appearance transitions for destination. This error occurs when you try and display a view controller before the current view controller is finished displaying. This may cause the UIViewController skips or messes up the order calling -viewWillAppear:, -viewDidAppear:, -viewWillDisAppear: and -viewDidDisappear:, and messes up the route state. Current error reason is already removed destination but destination appears again before -viewDidDisappear: 请问这个是什么原因?

commented

Unbalanced calls to begin/end appearance transitions for some ViewController is error from UIKit. Maybe you try to display a new view controller before the current view controller is finished displaying.
See https://stackoverflow.com/a/9088959/6380485.

You can reproduce this error with ZIKRouterDemo's ZIKCustomTransitionSegue.m:

    UIViewController *source = self.sourceViewController;
    UIViewController *destination = self.destinationViewController;

// Unbalanced transition 1
    destination.view.frame = source.view.frame;
    [source.view addSubview:destination.view];
    destination.view.transform = CGAffineTransformMakeScale(0.1, 0.1);
    [UIView animateWithDuration:2 animations:^{
        destination.view.transform = CGAffineTransformIdentity;
    } completion:^(BOOL finished) {
        [destination.view removeFromSuperview];
        //removeFromSuperview will call viewWillDisAppear: and viewDidDisappear: asyncly, so -presentViewController:animated:completion: here will lead to unbalanced transition
        [source presentViewController:destination animated:NO completion:^{
            
        }];
    }];

The presentViewController:animated:completion: will fail, because the removing action from removeFromSuperview is not finished yet.

Where did you get this error? Is it from the demo?