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?
Wangyue How is Mount Tai? The green of Qi and Lu ...
Before sharing your content, please consider the ...
Why is it that even though some products are rare...
Audiences who have watched Nolan's "Inter...
Recently, Douyin released the "2020 Spring F...
The planning of offline activities is similar to ...
“I brush my teeth three to five times a day, when...
In September 2021, the Tianjin Institute of Indus...
The temperature dropped a while ago and I had a s...
Why do rockets need to be transported by ship? Wh...
Source: Xinhua News Agency Client Producer: Sun Z...
This activity was based on the WeChat service acc...
Produced by: Science Popularization China Produce...