Detect whether iphone is of notch screen or normal rectangle screen to avaid navigation bar size issue?

梦想与她 提交于 2019-12-11 17:53:28

问题


I am facing an issue in implementing expandable banner on top like whatsapp do in profile screen. When user scroll image squeezes and convert into navigation bar. For that i have to set minimum height in my code but due to notch screen in iphone X and other new iphones it causing issue. Because old iphone doesnot have notch screen so there navigation bar height is less than new iphones?

So there is any way to find out the iphone is notch screen or normal type screen?


回答1:


This way you can detect notch screen:

extension UIDevice {
    var hasNotch: Bool {
        let bottom = UIApplication.shared.keyWindow?.safeAreaInsets.bottom ?? 0
        return bottom > 0
    }
}

if UIDevice.current.hasNotch {
            // consider notch
        } else {
            // don't have to consider notch
        }


来源:https://stackoverflow.com/questions/53779671/detect-whether-iphone-is-of-notch-screen-or-normal-rectangle-screen-to-avaid-nav

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!