简体   繁体   English

弹出框阴影随 iOS 13 消失

[英]Popover shadow gone with iOS 13

On devices running iOS 13, the popover shadow is no longer shows.在运行 iOS 13 的设备上,不再显示弹出阴影。 This happens when the popover is shown on a ViewController that contains a custom UIView with a CAEAGLLayer backing layer directly under it.当弹出框显示在包含自定义 UIView 且 CAEAGLLayer 支持层直接位于其下方的 ViewController 上时,就会发生这种情况。

I know CAEAGLLayer is deprecated in iOS 13 but there must be a way to resolve this.我知道 CAEAGLLayer 在 iOS 13 中已弃用,但必须有办法解决这个问题。

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.我尝试创建一个自定义 UIPopoverBackgroundView 并且其中设置的阴影效果很好。

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.好吧,对于那些遇到类似情况的人,我可以通过在视图控制器的 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;
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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