在iOS 7中,使用UIModalPresentationCurrentContext进行动画模式演示并不会产生动画效果

时间:2015-01-18 19:04:34

标签: ios animation ios7 presentmodalviewcontroller presentviewcontroller

在iOS 8中,当呈现模态(比方说透明背景)时,我们需要设置segue(或模态)以使用UIModalPresentationOverCurrentContext的呈现样式。这是按预期工作的。

要完成iOS 7的相同操作,您需要将呈现视图控制器设置为具有UIModalPresentationCurrentContext的模式演示样式。这是我遇到问题的地方。我用动画呈现模态,但它没有动画效果。提交后,一切正常,甚至动画解雇。此外,如果我将演示文稿样式更改为UIModalPresentationFullScreen,它会正确动画。

我已经四处搜索并阅读其他帖子,但我无法找到原因或解决方法。

1 个答案:

答案 0 :(得分:1)

  ViewController *vcObj = [[ViewController alloc] initWithNibName:NSStringFromClass([ViewController class]) bundle:nil];
    UINavigationController *navCon = [[UINavigationController alloc] initWithRootViewController:vcObj];

    if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {

        navCon.providesPresentationContextTransitionStyle = YES;
        navCon.definesPresentationContext = YES;
        navCon.modalPresentationStyle = UIModalPresentationOverCurrentContext;

        [self presentViewController:navCon animated:NO completion:nil];
    }
    else {

        AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
        [self presentViewController:navCon animated:NO completion:^{
            [navCon dismissViewControllerAnimated:NO completion:^{
                appDelegate.window.rootViewController.modalPresentationStyle = UIModalPresentationCurrentContext;
                [self presentViewController:navCon animated:NO completion:nil];
                appDelegate.window.rootViewController.modalPresentationStyle = UIModalPresentationFullScreen;

            }];
        }];
    }
相关问题