dismissViewControllerAnimated在ios8和ios7中有所不同

时间:2014-10-15 04:16:22

标签: ios8 xcode6

我有一个launchViewController A和另外两个视图控制器B和C.在app中,当前序列是A-> B-> C.我也需要解雇C并直接回到A.

问题是: 在iOS7中,我在A中调用[self dismissViewControllerAnimated:false completion:^{}]。不会调用B视图控制器中的函数viewWillAppearviewDidAppear

但在iOS8中,情况有所不同。将在B视图控制器中调用viewWillAppearviewDidAppear。当解雇时,这会导致B的内容闪烁。

任何人都可以帮我找到解决此问题的方法。

2 个答案:

答案 0 :(得分:2)

如果你想解雇你应该使用的当前ViewController

[self.presentingViewController dismissViewControllerAnimated:false completion:^{}]

 instead of [self dismissViewControllerAnimated:false completion:^{}]

答案 1 :(得分:0)

我用这个解决了这个问题:

- (void)dismissDeepViewControllerAnimated: (BOOL)flag completion: (void (^)(void))completion {
    if([UIDevice currentDevice].systemVersion.floatValue >= IOSCapVersion){
        UIView *window = ((AppDelegate *)[UIApplication sharedApplication].delegate).window;
        UIView *view = [window snapshotViewAfterScreenUpdates:false];
        [((AppDelegate *)[UIApplication sharedApplication].delegate).window addSubview:view];

        [self dismissViewControllerAnimated:false completion:^{
            [UIView animateWithDuration:AnimationDurationDismissViewController animations:^{
                view.alpha = 0;
            }completion:^(BOOL finished) {
                if (finished) {
                    [view removeFromSuperview];
                }
            }];

            completion();
        }];
    }
    else{
        [self dismissViewControllerAnimated:flag completion:^{
            completion();
        }];
    }
}