iOS 8 - 使用自定义演示关闭视图控制器后屏幕空白 [英] iOS 8 - Screen blank after dismissing view controller with custom presentation

查看:15
本文介绍了iOS 8 - 使用自定义演示关闭视图控制器后屏幕空白的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当使用 UIModalPresentationCustom 关闭各种视图控制器时,关闭视图控制器后屏幕变黑,就好像所有视图控制器都已从视图层次结构中删除一样.

When dismissing various view controllers using UIModalPresentationCustom, the screen turns black after the view controller is dismissed, as if all the view controllers had been removed from the view hierarchy.

transitioning delegate 设置正确,animationControllerForPresentedController 被请求并正确传递,动画结束后transition 完成.

The transitioning delegate is set properly, the animationControllerForPresentedController is asked for and passed correctly, and the transition is completed once the animation is over.

这个确切的代码在使用 iOS 7 SDK 编译时可以完美运行,但在使用 iOS 8b5 编译时会损坏

This exact code works perfectly when compiled with the iOS 7 SDK, but is broken when compiled with iOS 8b5

推荐答案

这是因为你很可能同时添加了演示文稿

This is because you are most likely adding both the presenting

[transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey]

和呈现的

[transitionContext viewControllerForKey:UITransitionContextToViewControllerKey]

在动画控制器的 (void)animateTransition:(id )transitionContext 方法中查看控制器到您的 containerView.由于您使用的是自定义模态展示,展示视图控制器仍显示在展示的视图控制器下方.现在因为它仍然可见,您不需要将它添加到容器视图中.而是只将呈现的视图控制器添加到 containerView.在你的 animateTransition: 方法中应该看起来像这样

view controllers to your containerView in the (void)animateTransition:(id )transitionContext method of your animation controller. Since you are using a custom modal presentation, the presenting view controller is still shown beneath the presented view controller. Now since it's still visible you don't need to add it to the container view. Instead only add the presented view controller to the containerView. Should look something like this inside of your animateTransition: method

UIView *containerView = [transitionContext containerView];
UIViewController *fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
UIViewController *toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];

// Boolean value to determine presentation or dismissal animation
if (self.presenting){        
    [transitionContext.containerView addSubview:toViewController.view];
    // Your presenting animation code
} else {
    // Your dismissal animation code
}

这篇关于iOS 8 - 使用自定义演示关闭视图控制器后屏幕空白的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆