简体   繁体   中英

Popover shadow gone with iOS 13

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...

在此处输入图像描述

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];

在此处输入图像描述

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

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;
        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM