After a long time, today I finally have time to summarize the pitfalls related to adapting to iPhone X. Generally speaking, there are two kinds of pitfalls. One is that the height of the navigation bar + status bar has changed, and the other is that some UITableViews that do not implement proxy methods such as -tableView: viewForHeaderInSection: and -tableView: viewForFooterInSection: will be misplaced. 1. Determine whether it is an iPhone X: Return YES or NO 1.1 Judgment: Macro (1) Based on screen resolution Trinocular algorithm
Multi-line logical judgment
Among them, the backslash \ is not a comment or other useless symbol, but a necessary symbol for multi-line macro line breaks. ***The sentence tmp;\ is also necessary, because the tmp obtained through logical judgment is used as the return value of the macro. (2) Based on screen size
1.2 Judgment: Method Method: According to the device model
2. Flexible return status bar + navigation bar height Requirement: Flexibly obtain the height of the navigation bar + status bar as the starting point of the Y axis of a subview. Macro Definition
Calling Example
3. Extension: Get iOS system and App version information Get iOS system version number: Returns a string
Get App version number: Returns a string
4. Other issues related to iPhone X adaptation In the process of adapting to iPhone X and Xcode 9, in addition to problems related to the navigation bar, another problem that often occurs is the problem related to UITableView. The following two methods can solve most of the misalignment problems. When VC creates tableView properties, set it like this
You can also set
About the safe area of the root view iOS has added a safeArea. In the old code, the code that specifies the relationship between the subview and the root subview needs to add a judgment: when iOS 11 is released, it needs to be changed to the relationship between the subview and the root subview's safe area. In this way, there will be no interference from any controls on the virtual home at the bottom of the iPhone X.
Of course, except for the tabbar, other views such as tableView or web page view can be placed in the bottom virtual home area. At this time, there is no need to emphasize that the subview must be placed in the safeArea, and the original old code does not need to be changed. |
<<: [Live] Technology or management, how should programmers plan their career path?
>>: After another year of tinkering, what is the dilemma facing WeChat Mini Programs?
A recent report that Windows may become open sour...
Shanghai Mylike is the earliest group enterprise ...
A major change in iOS 9 is the addition of multit...
[[248882]] Image source: Visual China While we st...
It is said that the three treasures of losers are...
How can an automaker prove that it is serious abo...
Four national departments jointly issued a docume...
Editor's note: Plants occupy a very important...
Today, the "dual carbon" goals of carbo...
If you follow the mobile phone industry, you must...
Xiaomi's phenomenal growth over the past few ...
In winter, the heating in our north makes the ind...
Zheng Xiangzhou-New Business Model Complete Works...
In November 2011, three months after the release ...
Oxygen was formerly known as "nourishing air...