美文网首页
ios安全区域高度

ios安全区域高度

作者: 小虾57 | 来源:发表于2024-04-17 16:19 被阅读0次
    // 顶部安全区高度
    + (CGFloat)dev_safeDistanceTop {
       if (@available(iOS 13.0, *)) {
           NSSet *set = [UIApplication sharedApplication].connectedScenes;
           UIWindowScene *windowScene = [set anyObject];
           UIWindow *window = windowScene.windows.firstObject;
           return window.safeAreaInsets.top;
       } else if (@available(iOS 11.0, *)) {
           UIWindow *window = [UIApplication sharedApplication].windows.firstObject;
           return window.safeAreaInsets.top;
       }
       return 0;
    }
    
    //顶部状态栏高度(包括安全区)
    + (CGFloat)dev_statusBarHeight {
       if (@available(iOS 13.0, *)) {
           NSSet *set = [UIApplication sharedApplication].connectedScenes;
           UIWindowScene *windowScene = [set anyObject];
           UIStatusBarManager *statusBarManager = windowScene.statusBarManager;
           return statusBarManager.statusBarFrame.size.height;
       } else {
           return [UIApplication sharedApplication].statusBarFrame.size.height;
       }
    }
    // 底部安全区高度
    + (CGFloat)dev_safeDistanceBottom {
       if (@available(iOS 13.0, *)) {
           NSSet *set = [UIApplication sharedApplication].connectedScenes;
           UIWindowScene *windowScene = [set anyObject];
           UIWindow *window = windowScene.windows.firstObject;
           return window.safeAreaInsets.bottom;
       } else if (@available(iOS 11.0, *)) {
           UIWindow *window = [UIApplication sharedApplication].windows.firstObject;
           return window.safeAreaInsets.bottom;
       }
       return 0;
    } 
    
    // 导航栏高度
    + (CGFloat)dev_navigationBarHeight {
       return 44.0f;
    }
    
    // 状态栏+导航栏的高度
    + (CGFloat)dev_navigationFullHeight {
       return [UIDevice dev_statusBarHeight] + [UIDevice dev_navigationBarHeight];
    }
    
    // 底部导航栏高度
    + (CGFloat)dev_tabBarHeight {
       return 49.0f;
    }
    
    // 底部导航栏高度(包括安全区)
    + (CGFloat)dev_tabBarFullHeight {
       return [UIDevice dev_statusBarHeight] + [UIDevice dev_safeDistanceBottom];
    }
    

    相关文章

      网友评论

          本文标题:ios安全区域高度

          本文链接:https://www.haomeiwen.com/subject/gmtexjtx.html