//iPhoneX 底部距离CGFloat adjust = 0; if (@available(iOS 11.0, *)) { //Account for possible notch UIEdgeInsets safeArea = [[UIApplication sharedApplication] keyWindow].safeAreaInsets; adjust = safeArea.bottom; }
所以现在只是需要设计师给2张效果图: iPhone XR:828px x 1792px iPhone XS Max: 1242px x 2688px
Tips
1. 代码中判断是否是iPhone X时需要注意
如果你以前是使用设备尺寸来判断iPhone X那就需要修改了,判断iPhone X主要是因为刘海的原因可能要做些特殊处理。鉴于iPhone X/XS/XR/XS Max底部都会有安全距离,所以可以利用safeAreaInsets.bottom > 0.0
来判断是否是iPhone X/XS/XR/XS Max。
safeAreaInsets支持iOS11及以后。
static inline BOOL isIPhoneXSeries() { BOOL iPhoneXSeries = NO; if (UIDevice.currentDevice.userInterfaceIdiom != UIUserInterfaceIdiomPhone) { return iPhoneXSeries; } if (@available(iOS 11.0, *)) { UIWindow *mainWindow = [[[UIApplication sharedApplication] delegate] window]; if (mainWindow.safeAreaInsets.bottom > 0.0) { iPhoneXSeries = YES; } } return iPhoneXSeries;}