swift – iOS: How can I place app logo under an iphone notch?


I have a task to place app logo under an iphone notch as it was implemented in telegram a few years ago.
logo under notch
So I need a way to check if app has notch or dynamic island and get its size. How can I do this?
I have found the code for checking if app has a notch, but not sure if it’s ok.

var hasTopNotch: Bool {
    if #available(iOS 11.0, tvOS 11.0, *) {
        return UIApplication.shared.delegate?.window??.safeAreaInsets.top ?? 0 > 20
    }
    return false
}
class LogoWindow: UIWindow {
    private let logoImageView = UIImageView(image: UIImage(named: "AppLogo"))

    override init(frame: CGRect) {
        super.init(frame: frame)
        commonInit()
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        commonInit()
    }
    
    private func commonInit() {
        //how to check if app has a notch or dynamic island ??
        //how to get frame of this notch or dynamic island??

        logoImageView.frame = CGRect(x: 10, y: 10, width: 60, height: 30)
        logoImageView.layer.zPosition = CGFloat(Float.greatestFiniteMagnitude)
        addSubview(logoImageView)
    }
}

Latest articles

spot_imgspot_img

Related articles

Leave a reply

Please enter your comment!
Please enter your name here

spot_imgspot_img