ios 获取导航栏和状态栏高度,针对iPhoneX

因为iPhoneX的产生,原本的导航栏再也不是44了,那么会出现什么问题呢?在隐藏导航栏的页面,原本的高度要向上调整一个导航栏+状态栏的高度。那么iPhoneX的导航栏高度不是44了,我们需要手动获取,

有导航栏的,代码如下:


1

2

3

4

5

6

//获取状态栏的rect

CGRect statusRect = [[UIApplication sharedApplication] statusBarFrame];

//获取导航栏的rect

CGRect navRect = self.navigationController.navigationBar.frame;

那么导航栏+状态栏的高度

statusRect.size.height+navRect.size.height

是不是很简单!!!!

对于项目有的很多处都需要这个代码,可以给它写成宏定义。如下

方法一:


1

2

//获取导航栏+状态栏的高度

#define getRectNavAndStatusHight  self.navigationController.navigationBar.frame.size.height+[[UIApplication sharedApplication] statusBarFrame].size.height

方法二:(用了宏定义的 参数返回)


1

2

3

4

5

6

//获取导航栏+状态栏的高度

#define getRectNavAndStatusHight \

({\

CGRect rectStatus = [[UIApplication sharedApplication] statusBarFrame];\    CGRect rectNav = self.navigationController.navigationBar.frame;\

( rectStatus.size.height+ rectNav.size.height);\

})\

下面说说没有导航栏(对于模态视图推出):

#define isPhoneX ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) : NO)

首先判断机型是不是iPhoneX,然后

如果是iPhoneX返回88 如果不是64

原文地址:https://www.cnblogs.com/Free-Thinker/p/9516613.html

时间: 2024-08-07 21:18:11

ios 获取导航栏和状态栏高度,针对iPhoneX的相关文章

iOS 获取导航栏和状态栏的高度

CGRect rect = [[UIApplication sharedApplication] statusBarFrame]; 状态栏的高度: float status height =  rect.size.height; 导航栏的高度: float navigationheight = self.navigationController.navigationBar.frame.size.height;

iOS 7 教程:定制iOS 7中的导航栏和状态栏

目录(?)[-] iOS 7中默认的导航栏 设置导航栏的背景颜色 在导航栏中使用背景图片 定制返回按钮的颜 修改导航栏标题的字体 修改导航栏标题为图片 添加多个按钮 修改状态栏的风格 隐藏状态栏 总结 注:本文译自Customizing Navigation Bar and Status Bar in iOS 7 近期,跟大多数开发者一样,我也正忙于对程序进行升级以适配iOS 7.最新的iOS 7外观上有大量的改动.从开发者的角度来看,导航栏和状态栏就发生了明显的变化.状态栏现在是半透明的了,这

定制iOS 7中的导航栏和状态栏

本文转载至 http://www.cocoachina.com/industry/20131104/7287.html 跟大多数开发者一样,我也正忙于对程序进行升级以适配iOS 7.最新的iOS 7外观上有大量的改动.从开发者的角度来看,导航栏和状态栏就发生了明显的变化.状态栏现在是半透明的了,这也 “” 阅读器 近期,跟大多数开发者一样,我也正忙于对程序进行升级以适配iOS 7.最新的iOS 7外观上有大量的改动.从开发者的角度来看,导航栏和状态栏就发生了明显的变化.状态栏现在是半透明的了,这

【转】【iOS】导航栏那些事儿

原文网址:http://www.jianshu.com/p/f797793d683f 参考文章 navigationItem UINavigationItem UINavigationBar UIBarButtonItem UIButton iOS 7 教程:定制iOS 7中的导航栏和状态栏 前言 本文试图阐释清楚导航栏相关的概念和用法,比如UINavigationBar和UINavigationItem的区别和联系,UIBarButtonItem的用法以及在纯代码和storyboard中有什么

Android 4.4 上实现透明导航栏和状态栏 Translucent system bar

Translucent system UI styling To get the most impact out of your content, you can now use new window styles and themes to request translucent system UI, including both the status bar and navigation bar. To ensure the legibility of navigation bar butt

iOS 为导航栏自定义按钮图案Button Image 运行出来的颜色与原本颜色不一样 -解决方案

为相机制作闪光灯,在导航栏自定义了"闪光"图案,希望点击时变换图片,但是一直没有改变,原来是因为设置了Global Tint的颜色,所以系统会自动把图片的颜色改为Global Tint的颜色. 解决方案,设置图片时,添加:imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal 源码: - (void) setFlashOn:(BOOL)isOn { if (self.captureDevice.hasFlash) { UIIm

统一设置导航栏与状态栏代码

统一设置导航栏与状态栏代码: #import "AppDelegate.h" #import "SZMMainTabBarController.h" @interface AppDelegate () @end @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launch

Android 动态隐藏显示导航栏,状态栏

Talk is cheap, show me the code. --Linus Torvalds Okay, here: 一.导航栏: [java] view plain copy private void hideNavigationBar() { View decorView = getWindow().getDecorView(); int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULL

iOS 去掉导航栏的边界黑线&去掉搜索框的边界黑线和其中文本输入框的阴影 - 解决方案

去掉导航栏的边界黑线 in viewDidload: [self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault]; self.navigationController.navigationBar.shadowImage = [[UIImage alloc] init]; 去掉搜索框的边界黑线 in viewDidload: