I have attached a video demonstrating the issue. It is very subtle but it's very apparent. It happens on both a simulator and a real device but is more likely on a real device.
When I dismiss ViewController2, the pixels of the visual effect view of the welcomeVc at the very bottom disappears for a split second before reappearing.
Here is a minimum reproducible example. I hope I could get across the effect I am trying to go for.
class ViewControllerStack {
static let shared = ViewControllerStack()
var views: [UIViewController] = []
}
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
view = MKMapView()
}
override func viewDidAppear(_ animated: Bool) {
let welcomeVC = WelcomeViewController()
welcomeVC.isModalInPresentation = true
if let sheet = welcomeVC.sheetPresentationController {
sheet.detents = [.custom(resolver: { context in
return 200
}), .medium()]
sheet.prefersGrabberVisible = true
sheet.preferredCornerRadius = 15
sheet.largestUndimmedDetentIdentifier = .medium
}
present(welcomeVC, animated: true)
ViewControllerStack.shared.views.append(welcomeVC)
}
}
class WelcomeViewController: UIViewController {
override func viewDidLoad() {
let blurEffect = UIBlurEffect(style: .systemThinMaterial)
let blurEffectView = UIVisualEffectView(effect: blurEffect)
blurEffectView.frame = view.bounds
view.addSubview(blurEffectView)
view.sendSubviewToBack(blurEffectView)
let button = UIButton()
button.setTitle("Go to View Controller 2", for: .normal)
button.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)
button.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(button)
NSLayoutConstraint.activate([
button.centerXAnchor.constraint(equalTo: view.centerXAnchor),
button.centerYAnchor.constraint(equalTo: view.centerYAnchor),
button.widthAnchor.constraint(equalToConstant: 200),
button.heightAnchor.constraint(equalToConstant: 44)
])
}
@objc func buttonTapped() {
let vc2 = ViewController2()
vc2.modalPresentationStyle = .overCurrentContext
vc2.modalTransitionStyle = .coverVertical
present(vc2, animated: true) {
UIView.animate(withDuration: 0.75) {
self.view.alpha = 0
}
}
ViewControllerStack.shared.views.append(vc2)
}
}
class ViewController2: UIViewController {
override func viewDidLoad() {
let blurEffect = UIBlurEffect(style: .systemThinMaterial)
let blurEffectView = UIVisualEffectView(effect: blurEffect)
blurEffectView.frame = view.bounds
view.addSubview(blurEffectView)
view.sendSubviewToBack(blurEffectView)
let button = UIButton()
button.setTitle("Go back to Welcome VC", for: .normal)
button.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)
button.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(button)
NSLayoutConstraint.activate([
button.centerXAnchor.constraint(equalTo: view.centerXAnchor),
button.centerYAnchor.constraint(equalTo: view.centerYAnchor),
button.widthAnchor.constraint(equalToConstant: 200),
button.heightAnchor.constraint(equalToConstant: 44)
])
}
@objc func buttonTapped() {
ViewControllerStack.shared.views.removeLast()
guard let lastVCInStack = ViewControllerStack.shared.views.last else { return }
lastVCInStack.dismiss(animated: true)
lastVCInStack.view.alpha = 1
}
}