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?
Why do fish swim with their heads down? Is it bec...
Produced by: Science Popularization China Author:...
On the evening of May 11, Bloomberg published an ...
Speaking of the Great Wall, everyone knows that t...
Skin care products have become a necessity in our...
As the Wuhan epidemic gradually recedes, companie...
Between bidding promotion and information flow ad...
It is now March, and the official release of Andr...
In order for an activity to be successful, adequa...
About the author: Bao Xiehao, Xiaomi MIUI departm...
Workers usually stay up late to work overtime, an...
Course Catalog: ├──Wang Chong 1.1.mp4 1.11G ├──Wa...
Hprose is an advanced lightweight cross-language ...
Previously, we already had a very deep understand...
Cities are at the forefront of China's new en...