我有一个AccountViewController,其UIVisualEffectView
在背景中具有模糊效果(索引为0的子视图),因此它在转换过程中覆盖了前一个带模糊的控制器。但是,当我再切换到另一个应用程序并再次打开多任务菜单切换回我的应用程序时,其模糊的UIVisualEffectView似乎已损坏(如屏幕截图1所示)。当我再次激活我的应用程序时,视图会“修复”并再次显示正常(如第二个屏幕截图所示)
我自定义转换类中的一些代码,我添加了模糊视图
// 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)
})
}
答案 0 :(得分:0)
似乎我自己已经弄明白了:只有当UIWindow返回(黑色)显示时才会出现此问题。 在这个问题中,我有一个包含这些视图的过渡动画容器:
由于fromViewController的视图大小(由于缩放变换而小于屏幕),黑色UIWindow视图显示出来。根据我的研究,这会导致UIVisualEffectView产生这个问题中描述的故障。
解决方案是添加一个带有UIWindow框架的黑色UIView,并将其添加到容器视图层次结构的底部:
let blackView = UIView(frame: container.frame)
blackView.backgroundColor = UIColor.blackColor()
container.insertSubview(blackView, atIndex: 0)
然后这个故障似乎不再出现了。