简体   繁体   中英

iOS 13 UIViewController modal presentation shadow

I have modaly presented view controller in iOS >=13. 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:

在此处输入图像描述

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/

For my own apps/games I'll be looking to create a custom UIModalPresentationStyle to achieve the look I want.

You can also alleviate from this by simply presenting as.fullScreen or another presentation style instead of this new sheet method.


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. I cannot find how to fix this on iPad. override 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.

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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