iOS 13后,气泡弹出框的阴影消失了。

4
在运行iOS 13的设备上,弹出窗口的阴影不再显示。当弹出窗口显示在一个ViewController上时,该ViewController包含一个直接位于其下方的自定义UIView,并带有CAEAGLLayer后备层。
我知道CAEAGLLayer在iOS 13中已被弃用,但一定有解决方法。
有趣的是,当截取屏幕截图以展示此问题时,阴影会显示在屏幕截图上!太奇怪了...

enter image description here

我尝试创建一个自定义的UIPopoverBackgroundView,并且其中设置的阴影效果运行良好。
UIPopoverPresentationController *popoverController = viewController.popoverPresentationController;
popoverController.permittedArrowDirections = UIPopoverArrowDirectionDown;
popoverController.popoverBackgroundViewClass = [PopoverBackgroundView class];

enter image description here

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

似乎这个项目需要从OpenGL更改为苹果的3D图形API:Metal。 - hong developer
是的,最终可能会这样,但目前不打算做如此大的更改。该死的苹果... - Jona
+1:我这里也完全一样的问题,包括阴影在截图中神奇地出现!我做了一些实验,发现结果不一,但有时更改图层的opaque属性可以恢复阴影,有时将一个不可见视图添加到窗口也可以达到同样的效果。不幸的是,两者都不足以在所有情况下解决问题。我会尝试你的解决方法... - deltacrux
1个回答

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

1
+1:这太棒了!我最终交换了 UIViewControllerviewWillAppear: 方法,这样我就不必将此代码添加到所有我的弹出窗口中,它完美地工作。非常感谢您发布这个! :) - deltacrux

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接