iOS 8 - 在关闭具有自定义演示文稿的视图控制器之后,屏幕空白 [英] iOS 8 - Screen blank after dismissing view controller with custom presentation

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

问题描述

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

正确设置转换委托,调用animationControllerForPresentedController并正确传递,并且一旦动画结束就完成转换。



这个精确的代码在使用iOS 7 SDK编译时可以很好地工作,但是在使用iOS 8b5编译时会崩溃

解决方案

这是因为你很可能添加了



[transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey] / code>



和显示的



[transitionContext viewControllerForKey:UITransitionContextToViewControllerKey ]



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

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

//确定显示或关闭动画的布尔值
if(self.presenting){
[transitionContext.containerView addSubview:toViewController.view];
//您的演示动画代码
} else {
//您的解雇动画代码
}


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.

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

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]

and the presented

[transitionContext viewControllerForKey:UITransitionContextToViewControllerKey]

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天全站免登陆