iOS get navigation bar and status bar height for Iphonex

Source: Internet
Author: User

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 //获取状态栏的rectCGRect statusRect = [[UIApplication sharedApplication] statusBarFrame];//获取导航栏的rectCGRect 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.