繁体   English   中英

弹出框阴影随 iOS 13 消失

[英]Popover shadow gone with iOS 13

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

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

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

在此处输入图像描述

我尝试创建一个自定义 UIPopoverBackgroundView 并且其中设置的阴影效果很好。

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

在此处输入图像描述

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

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