简体   繁体   English

iOS 13 UIViewController 模态表示阴影

[英]iOS 13 UIViewController modal presentation shadow

I have modaly presented view controller in iOS >=13.我已经在 iOS >=13 中展示了视图 controller。 Root view has clear background:根视图具有清晰的背景:

view.backgroundColor = .clear

Child view with white background has some top offset like this:白色背景的子视图有一些顶部偏移,如下所示:

在此处输入图像描述

All is ok, but when I try to dismiss it by swipe down I see slightly visible shadow of presented view controller:一切正常,但是当我尝试通过向下滑动将其关闭时,我看到呈现视图 controller 的略微可见阴影:

在此处输入图像描述

Is it posible to remove this shadow on modal presentation?是否可以在模态演示中消除这种阴影?

UPDATE: Upon further investigation, this does not appear to be something that can be changed.更新:经过进一步调查,这似乎不是可以改变的。 It's a private UIKit View setup by iOS and is a new addition in iOS 13. See 19:50 at https://developer.apple.com/videos/play/wwdc2019/224/ It's a private UIKit View setup by iOS and is a new addition in iOS 13. See 19:50 at https://developer.apple.com/videos/play/wwdc2019/224/

For my own apps/games I'll be looking to create a custom UIModalPresentationStyle to achieve the look I want.对于我自己的应用程序/游戏,我将寻求创建一个自定义 UIModalPresentationStyle 来实现我想要的外观。

You can also alleviate from this by simply presenting as.fullScreen or another presentation style instead of this new sheet method.您还可以通过简单地呈现 as.fullScreen 或其他呈现样式而不是这种新的工作表方法来缓解这种情况。


I have been trying to find the answer to this myself.我一直在努力寻找自己的答案。 So far I have only found that by setting the layer.shadowColor to clear it fixes this but only on iPhone.到目前为止,我只发现通过设置 layer.shadowColor 来清除它可以解决这个问题,但仅限于 iPhone。 I cannot find how to fix this on iPad.我在 iPad 上找不到如何解决此问题。 override func viewDidLoad() { view.layer.shadowColor = UIColor.clear.cgColor }覆盖 func viewDidLoad() { view.layer.shadowColor = UIColor.clear.cgColor }

I have solution for you我有你的解决方案

extension UIViewController {
    func removeBackgroundForParents() {
        var superview = view.superview
        while superview != nil {
            superview?.layer.backgroundColor = UIColor.clear.cgColor
            superview?.layer.shadowColor = UIColor.clear.cgColor
            superview = superview?.superview
        }
    }
}

And use it in your view controller.并在您的视图中使用它 controller。

override func viewDidLayoutSubviews() {
    super.viewDidLayoutSubviews()
    
    removeBackgroundForParents()
}

You can't remove the shadow from the default modal presentation.您无法从默认模式演示文稿中删除阴影。 But you are free to write your own custom transition animation with custom presentation controller, and in that case it is up to you whether you insert a shadow view (dimming view).但是您可以自由地编写自己的自定义过渡 animation 和自定义演示 controller,在这种情况下,是否插入阴影视图(调光视图)取决于您。

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

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