60 lines
1.3 KiB
Swift
60 lines
1.3 KiB
Swift
//
|
|
// CheckPhoneHomeBtnOrNotch.swift
|
|
// WOKA
|
|
//
|
|
// Created by MacBook Pro on 29/04/24.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
enum DeviceTypeEnum{
|
|
case notch
|
|
case homeButton
|
|
case notFound
|
|
}
|
|
class CheckPhoneHomeBtnOrNotch{
|
|
|
|
static let shareInstance = CheckPhoneHomeBtnOrNotch()
|
|
|
|
func check() -> DeviceTypeEnum{
|
|
switch UIDevice().hasNotch{
|
|
case true:
|
|
return .notch
|
|
case false:
|
|
return .homeButton
|
|
}
|
|
}
|
|
|
|
func topConstriant() -> CGFloat{
|
|
switch CheckPhoneHomeBtnOrNotch.shareInstance.check(){
|
|
case .notch:
|
|
return 40
|
|
case .homeButton:
|
|
return 15
|
|
case .notFound:
|
|
return 0
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
extension UIDevice {
|
|
var hasNotch: Bool {
|
|
if #available(iOS 13.0, *) {
|
|
let scenes = UIApplication.shared.connectedScenes
|
|
let windowScene = scenes.first as? UIWindowScene
|
|
guard let window = windowScene?.windows.first else { return false }
|
|
|
|
return window.safeAreaInsets.top > 20
|
|
}
|
|
|
|
if #available(iOS 11.0, *) {
|
|
let top = UIApplication.shared.windows[0].safeAreaInsets.top
|
|
return top > 20
|
|
} else {
|
|
// Fallback on earlier versions
|
|
return false
|
|
}
|
|
}
|
|
}
|