iOS 13 中弹出窗口的阴影消失了

Jon*_*ona 5 ios ios13

在运行 iOS 13 的设备上,弹出窗口阴影不再显示。当弹出窗口显示在包含自定义 UIView 且其正下方有 CAEAGLLayer 支持层的 ViewController 上时,会发生这种情况。

我知道 CAEAGLLayer 在 iOS 13 中已被弃用,但必须有办法解决这个问题。

有趣的是,在截取屏幕截图时,在这里显示屏幕截图上出现阴影的问题!太奇怪了...

在此输入图像描述

我尝试创建一个自定义 UIPopoverBackgroundView 并且其中的阴影集工作正常。

UIPopoverPresentationController *popoverController = viewController.popoverPresentationController;
popoverController.permittedArrowDirections = UIPopoverArrowDirectionDown;
popoverController.popoverBackgroundViewClass = [PopoverBackgroundView class];
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

任何提示或想法将不胜感激!我花了一整天的时间试图弄清楚这个问题。:/

Jon*_*ona 2

好吧,对于那些遇到类似问题的人,我可以通过在视图控制器的 viewWillDisplay 方法中使用以下方法来修补临时修复。

+ (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;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)