#define SAFE_AREA_INSETS_TOP safeAreaInsets().top

#define SAFE_AREA_INSETS_BOTTOM safeAreaInsets().bottom

UIEdgeInsets safeAreaInsets(void) {

    UIEdgeInsets safeAreaInsets = UIEdgeInsetsZero;

    if (@available(iOS 11.0, *)) {

        safeAreaInsets = [[[[UIApplication sharedApplication]
delegate]window]safeAreaInsets];

    }

    return safeAreaInsets;

}

打印查看:


NSLog(@"%f----%f----%f----%f",SAFE_AREA_INSETS_TOP,safeAreaInsets().top,SAFE_AREA_INSETS_BOTTOM,safeAreaInsets().bottom);