티스토리 뷰

IOS

Swift) How to detect notch scree

sulkun 2020. 9. 3. 22:17
반응형

안녕하세요 오늘은 노치 Or Safe Area를 사용이 가능한지

 

check 하는 방법을 알아보겠습니다..

 

최근 아이폰들이 6plus 까지 13.0 버전 이상 업데이트가 되면서

 

더이상 버전으로는 Safe Area를 사용하지 여부를 알수 없게되었습니다.

 

그래서 최근에 찾다가 알아낸사실을 

 

포스팅 할까 합니다.

 

https://medium.com/rosberryapps/ios-safe-area-ca10e919526f

 

https://medium.com/@cafielo/how-to-detect-notch-screen-in-swift-56271827625d

 

사진에서 볼수 있듯 Buttom 에는 계속 있는것을 확인해볼수 있습니다.

 

 

 


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 
}

확장해서 사용하시길 바래요.

 

반응형
댓글