2

I am implementing a popover view using UIPopoverPresentationController.

enter image description here

The trouble with this, is that by default, I have a shadow with a large radius for the controller.

I want to disable this - the overlay.

I have tried:

  1. to customise the layout shadow (using a UIPopoverBackgroundView):

    layer.shadowColor = UIColor.white.withAlphaComponent(0.01).cgColor
    layer.shadowOffset = .zero
    layer.shadowRadius = 0
    
  2. In view debugging - I can see behind the popup 4 image views with gray gradient background:

enter image description here

I am sure this is a default behaviour, of showing an overlay behind a popover.

How do disable this?

I found this and this. But those didn't helped.

Laura Calinoiu
  • 704
  • 1
  • 8
  • 24

1 Answers1

1

If you take a closer look at the views hierarchy you will notice that the shadow layer _UIMirrorNinePatchView is a sublayer of UITransitionView same as UIPopoverView - both are on the same level.

views hierarchy picture

In this case you can try to hide this sublayer like so:

override func viewDidLayoutSubviews() {
    super.viewDidLayoutSubviews()

    if let shadowLayer = UIApplication.shared.windows.first?.layer.sublayers?[1].sublayers?[1] {
        shadowLayer.isHidden = true
    }
}

Make sure to hide it in viewDidLayoutSubviews to avoid exceptions related to missing sublayers or sublayer flickering.

kpoznak
  • 11
  • 1
  • I didn't liked this solution, because it uses a UIApplication, and it has an ugly method of finding out that view. I was applying this to my app. It does work, although I can see some flickering. At the moment, I don't have another solution to this. @kpoznak, thanks – Laura Calinoiu Mar 20 '18 at 12:55