Because of the production of Iphonex, the original navigation bar is no longer 44, then what problems will arise? In the hidden navigation bar of the page, the original height to adjust the height of a navigation bar + status bar. So Iphonex's navigation bar height is not 44, we need to manually obtain,
With the navigation bar, the code is as follows:
123456 |
//获取状态栏的rect CGRect statusRect = [[UIApplication sharedApplication] statusBarFrame]; //获取导航栏的rect CGRect navRect = self.navigationController.navigationBar.frame; 那么导航栏+状态栏的高度 statusRect.size.height+navRect.size.height |
is not very simple!!!
This code is needed for many places in the project, and it can be written as a macro definition. As follows
Method One:
12 |
//获取导航栏+状态栏的高度 #define getRectNavAndStatusHight self.navigationController.navigationBar.frame.size.height+[[UIApplication sharedApplication] statusBarFrame].size.height |
Method Two: (returned with a macro-defined parameter)
123456 |
//获取导航栏+状态栏的高度 #define getRectNavAndStatusHight \ ({\ CGRect rectStatus = [[UIApplication sharedApplication] statusBarFrame];\ CGRect rectNav = self.navigationController.navigationBar.frame;\ ( rectStatus.size.height+ rectNav.size.height);\ })\ |
The following is no navigation bar (for modal view rollout):
#define ISPHONEX ([UIScreen instancesrespondtoselector: @selector (currentmode)]? Cgsizeequaltosize (Cgsizemake (1125, 2436), [[UIScreen Mainscreen] currentmode].size): NO)
First determine if the model is Iphonex, and then
If it is Iphonex returns 88 if not 64
iOS gets the navigation bar and status bar height for Iphonex