1

我有一个 AccountsViewController,它UIVisualEffectView在背景中具有模糊效果(索引 0 处的子视图),因此它在过渡期间用模糊覆盖了先前的控制器。但是当我切换到另一个应用程序并再次打开多任务菜单以切换回我的应用程序时,其模糊的 UIVisualEffectView 似乎已损坏(如屏幕截图 1 所示)。当我再次激活我的应用程序时,视图得到“修复”并且看起来再次正常(如第二个屏幕截图所示)

损坏的 UIVisualEffectView 选择应用程序后几毫秒内就可以了

我添加模糊视图的自定义转换类中的一些代码

// in the animateTransition.. method
guard let container = transitionContext.containerView() else {
            return
        }
let blurEffectView: UIVisualEffectView
        if container.viewWithTag(101) != nil {
            blurEffectView = container.viewWithTag(101)! as! UIVisualEffectView
        }
        else {
            blurEffectView = UIVisualEffectView(frame: container.frame)
            blurEffectView.translatesAutoresizingMaskIntoConstraints = false
            blurEffectView.tag = 101
            container.addSubview(blurEffectView)
        }

        if self.isPresenting {
            // We're presenting a view controller over another
            toViewController.view.transform = CGAffineTransformMakeScale(0.7, 0.7)
            container.addSubview(toViewController.view)
            container.sendSubviewToBack(blurEffectView)
            toViewController.view.alpha = 0

            UIView.animateWithDuration(self.transitionDuration(transitionContext), delay: 0, usingSpringWithDamping: 0.8, initialSpringVelocity: 0.8, options: [], animations: { () -> Void in
                fromViewController.view.transform = CGAffineTransformMakeScale(0.8, 0.8)
                toViewController.view.transform = CGAffineTransformMakeScale(1, 1)
                blurEffectView.effect = UIBlurEffect(style: .Dark)
                toViewController.view.alpha = 1
            }, completion: { (completed) -> Void in
                self.context?.completeTransition(completed)
            })
        }
        else {
            // We're dismissing a view controller
            UIView.animateWithDuration(self.transitionDuration(transitionContext), delay: 0, usingSpringWithDamping: 0.8, initialSpringVelocity: 0.8, options: [], animations: { () -> Void in
                fromViewController.view.transform = CGAffineTransformMakeScale(0.7, 0.7)
                toViewController.view.transform = CGAffineTransformMakeScale(1, 1)
                blurEffectView.effect = nil
                fromViewController.view.alpha = 0
            }, completion: { (completed) -> Void in
                fromViewController.view.removeFromSuperview()
                self.context?.completeTransition(completed)
            })
        }
4

1 回答 1

0

好像我自己已经弄清楚了:这个问题只有在 UIWindow 背面(黑色)显示出来时才会出现。在这个问题中,我有一个带有这些视图的过渡动画容器:

  • fromViewController 的视图(缩放变换为 0.8;0.8)
  • 应用了 .Dark 风格模糊的 UIVisualEffectView
  • toViewController 的视图

由于 fromViewController 的视图大小(由于比例变换而小于屏幕),黑色的 UIWindow 视图显示出来。根据我的研究,这会导致 UIVisualEffectView 产生此问题中描述的故障。

解决方案是添加一个带有 UIWindow 框架的黑色 UIView 并将其添加到容器视图层次结构的底部:

let blackView = UIView(frame: container.frame)
blackView.backgroundColor = UIColor.blackColor()
container.insertSubview(blackView, atIndex: 0)

然后这个故障似乎不再出现。

于 2016-04-01T19:49:57.460 回答