I have several tabs in my application (UITabBarController
), and in one of them I can show modal UIViewController with blur effect (over the current controller from tab).
let bVC = BlurViewController()
bVC.modalPresentationStyle = .overCurrentContext
self.present(bVC, animated: true, completion: nil)
Blurred controller is just a simple UIViewController
with this code in viewDidLoad
:
let blurEffect = UIBlurEffect(style: .extraLight)
let blurEffectView = UIVisualEffectView(effect: blurEffect)
blurEffectView.frame = self.view.frame
self.view.insertSubview(blurEffectView, at: 0)
The first problem I have here, other tabs are still accessible. User is able to tap on them without dismissing my blurred controller.
It's not a real problem, but when this user is back, my blurred viewcontroller has gray background. It's understandable, all areas behind it were not redrawn but it's a problem.
The third problem: if this user would try to close my blurred controller, the first controller is just black.
I know I can fight the last two problems with this:
dismiss blurred controller in
viewDidDisappear
.remember "the blurred state" in its parent controller.
if user is back, show blurred controller again.
But maybe there is a more elegant and simple approach?