Gentlemen, how to make the Navigation Bar and Status Bar blurred (UIBlurEffect)? When I click on the picture I scroll down (Scroll View) to other pictures, this picture (in this case with a white car) is simply lost under the Navigation Bar, and I need this picture to be visible under the Navigation Bar with the UIBlurEffect effect.
Not blurred Navigation Bar and Status Bar

I tried it, but it did not work:

func addBlurEffect() { // Add blur view let bounds = self.navigationController?.navigationBar.bounds as CGRect! let visualEffectView = UIVisualEffectView(effect: UIBlurEffect(style: .light)) visualEffectView.frame = bounds! visualEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight] self.navigationController?.navigationBar.addSubview(visualEffectView) self.navigationController?.navigationBar.sendSubview(toBack: visualEffectView) visualEffectView.isUserInteractionEnabled = false } 

First, when scrolling, the picture also disappears under the Navigation Bar.
Secondly, the Status Bar remained gray.
Status Bar did not apply UIBlurEffect

In order for the Status Bar to NOT remain gray, I tried to do it, but to no avail = (

 bounds.offsetBy(dx: 0.0, dy: -20.0) bounds.size.height = bounds.height + 20.0 

Also in AppDelegate (it is written in Objective-C in the application) in didFinishLaunchingWithOptions, I tried to add it, everything remained the same unchanged:

 [[UINavigationBar appearance] setBackgroundImage:[[UIImage alloc]init] forBarMetrics:UIBarMetricsDefault]; [[UINavigationBar appearance] setShadowImage:[[UIImage alloc]init]]; [[UINavigationBar appearance] setBackgroundColor:[UIColor colorWithRed:0.0f green:0.0f blue:0.0f alpha:0.0f]]; [[UINavigationBar appearance] setTranslucent:YES]; 

Please help solve the problem, I have been driving with it for 2 days already.

    1 answer 1

    The code that helped me, and especially the second line:

     let visualEffectView = UIVisualEffectView(effect: UIBlurEffect(style: .light)) visualEffectView.frame = (self.navigationController?.navigationBar.bounds.insetBy(dx: 0, dy: -10).offsetBy(dx: 0, dy: -10))! self.navigationController?.navigationBar.isTranslucent = true self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default) self.navigationController?.navigationBar.addSubview(visualEffectView)