Skip to content

Commit a45b0be

Browse files
authored
Update UIControlViewHelper.swift
1 parent b01d140 commit a45b0be

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

Sources/UIControlViewHelper.swift

+28
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,34 @@ class UIControlViewHelper {
5555
alpha: CGFloat(1.0)
5656
)
5757
}
58+
59+
//MARK: - padding
60+
public enum padding {
61+
case top
62+
case bottom
63+
}
64+
65+
//MARK: - getPadding(_ padding: padding)
66+
static func getPadding(_ padding: padding) -> CGFloat {
67+
if #available(iOS 15, *) {
68+
let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene
69+
switch padding {
70+
case .top:
71+
return (windowScene?.keyWindow?.safeAreaInsets.top)!
72+
case .bottom:
73+
return (windowScene?.keyWindow?.safeAreaInsets.bottom)!
74+
}
75+
} else {
76+
let window = UIApplication.shared.keyWindow
77+
switch padding {
78+
case .top:
79+
return window?.safeAreaInsets.top ?? 0
80+
case .bottom:
81+
return window?.safeAreaInsets.bottom ?? 0
82+
}
83+
}
84+
}
85+
5886
}
5987

6088
// MARK: - Detect gesture direction

0 commit comments

Comments
 (0)