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

标签 ios ios13

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

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

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

enter image description here

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

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

enter image description here

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

最佳答案

好吧,对于那些遇到类似问题的人,我可以通过在 View Controller 的 View WillDisplay 方法中使用以下方法来修补临时修复。

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

关于ios - iOS 13 中弹出窗口的阴影消失了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58443155/

相关文章:

objective-c - 在没有新初始化的情况下使用类中的数据

iphone - 如何为 iOS 创建像谷歌地图一样的用户卡片动画

swift - 为什么手动设置 Root View Controller 显示黑屏?

iOS 13 更新在首次显示时损坏了我的应用程序的键盘

swift - 前提条件失败 : invalid input index when using GeometryReader in SwiftUI starting with iOS 13. 4

ios13 - 在 PencilKit 中编辑 PKDrawing

ios - 在 Facebook 视频 IOS 中标记 friend

ios - 当我的 iOS 应用程序在后台使用 ReplayKit 时的屏幕录制

iOS 13 UITextView 将 UITextView 转换为图像无法正常工作。在 iOS 12 以下运行良好

ios - iOS 上的 mDNSResponder 错误