Popover shadow gone with iOS 13

Viewed 789

On devices running iOS 13, the popover shadow is no longer shows. This happens when the popover is shown on a ViewController that contains a custom UIView with a CAEAGLLayer backing layer directly under it.

I know CAEAGLLayer is deprecated in iOS 13 but there must be a way to resolve this.

Funny enough when taking a screenshot to show here the issue the shadow shows up on the screenshot! So weird...

enter image description here

I tried creating a custom UIPopoverBackgroundView and the shadow set in it worked fine.

UIPopoverPresentationController *popoverController = viewController.popoverPresentationController;
popoverController.permittedArrowDirections = UIPopoverArrowDirectionDown;
popoverController.popoverBackgroundViewClass = [PopoverBackgroundView class];

enter image description here

Any tips or ideas would be greatly appreciated! I spent all day trying to figure this one out. :/

1 Answers

Well, for those running into something similar I was able to patch a temp fix by using the following method inside the view controller's viewWillDisplay method.

+ (void)fixShadowForViewController:(UIViewController*)viewController
{
    if (viewController.popoverPresentationController)
    {
        NSOperatingSystemVersion ios13 = (NSOperatingSystemVersion){13, 0, 0};
        if ([[NSProcessInfo processInfo] isOperatingSystemAtLeastVersion:ios13])
        {
           UIView *popoverView = viewController.popoverPresentationController.containerView;
           popoverView.layer.shadowColor = [UIColor blackColor].CGColor;
           popoverView.layer.shadowOpacity = 0.16f;
           popoverView.layer.shadowOffset = CGSizeMake(0.0f, 0.0f);
           popoverView.layer.shadowRadius = 32.0f;
        }
        else
        {
            // The arrow doesn't get colored properly on iOS 12 and lower so we take the background
            // color of the view controller and apply it to make it match.
            viewController.popoverPresentationController.backgroundColor = viewController.view.backgroundColor;
        }
    }
}
Related