原文
iOS刘海手机屏幕的适配
判断是不是iphone x齐刘海屏幕
iOS开发 iPhoneX以上机型适配判断
判断iPhone X之后带刘海的机型
iOS11之后新增了一个safeAreaInsets属性
可以利用 CGFloat a = [[UIApplication sharedApplication] delegate].window.safeAreaInsets.bottom;
当a大于0时即是iPhone X ,XR,XS ,XS Max等。
if (@available(iOS 11.0, *)) {
CGFloat a = [[UIApplication sharedApplication] delegate].window.safeAreaInsets.bottom;
NSLog(@"%f",a);
} else {
// Fallback on earlier versions
}
#define IPHONE_X \
({BOOL isPhoneX = NO;\
if (@available(iOS 11.0, *)) {\
isPhoneX = [[UIApplication sharedApplication] delegate].window.safeAreaInsets.bottom > 0.0;\
}\
(isPhoneX);})
#define isIphoneX ({\
BOOL isPhoneX = NO;\
if (@available(iOS 11.0, *)) {\
if (!UIEdgeInsetsEqualToEdgeInsets([UIApplication sharedApplication].delegate.window.safeAreaInsets, UIEdgeInsetsZero)) {\
isPhoneX = YES;\
}\
}\
isPhoneX;\
})
swift
func isiPhoneXScreen() -> Bool {
guard #available(iOS 11.0, *) else {
return false
}
return UIApplication.shared.windows[0].safeAreaInsets != UIEdgeInsets.zero
}