Detailed ios11, iPhone x, xcode9 adaptation Guide

Time:2021-11-7

After updating ios11, it is found that some places need to be adapted. After sorting, it is divided into the following three categories according to priority:

  • Changes caused by simply upgrading ios11;
  • Changes caused by xcode9 packaging;
  • IPhone x adaptation

1、 Changes caused by simply upgrading ios11

After upgrading, it is found that the interface with a tableview is disordered, the group spacing and contentinset are disordered, because the automaticallyadjustscrollviewinsets property of uiviewcontroller in ios11 is discarded. Therefore, when the tableview exceeds the security zone, the system will automatically adjust the safeareainsets value, which will affect the adjustedcontentinset value

//Some interfaces use the following proxy method to set, and it is found that it does not take effect
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section;
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section;

//The reason for this principle is that the proxy method of view was not implemented before, and there is no problem with ios10 and the previous writing. Ios11 turns on the bug caused by the row height estimation mechanism. Therefore, there are the following solutions:

//Solution 1: add a proxy method to implement view
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
  return nil;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  return nil;
}

//Solution 2: set the tableview property directly to fix the UI disorder
self.tableView.sectionHeaderHeight = 0;
self.tableView.sectionFooterHeight = 5;

[_optionTableView setContentInset:UIEdgeInsetsMake(-35, 0, 0, 0)];

//Solution 3: add the following code to close the estimation line height
self.tableView.estimatedRowHeight = 0;
self.tableView.estimatedSectionHeaderHeight = 0;
self.tableView.estimatedSectionFooterHeight = 0;

4、 Problems found after compiling with xcode9

1. It is found that the third party of “fastsocket” reports an error. The specific reason is the lack of C99 header file. Just introduce “#include < sys / time. H >”


2. New features of navigation bar

The native search bar style has changed

On the right is ios11 style. The height of the search area becomes larger and the font becomes larger

After viewing the API, it is found that after ios11, the searchcontroller is assigned to the navigationitem. Whether the search bar is hidden and displayed when sliding can be controlled through the attribute hidesearchbarwhenscolling


// A view controller that will be shown inside of a navigation controller can assign a UISearchController to this property to display the search controller's search bar in its containing navigation controller's navigation bar.
@property (nonatomic, retain, nullable) UISearchController *searchController API_AVAILABLE(ios(11.0)) API_UNAVAILABLE(tvos);

// If this property is true (the default), the searchController's search bar will hide as the user scrolls in the top view controller's scroll view. If false, the search bar will remain visible and pinned underneath the navigation bar.

In addition, uinavigationbar adds the attribute bool value preferslargetitles to achieve the following effects, and you can set the text style of the headline through largetitletextattributes

In one interface, the frame related to the navigation bar button is used, and the UI is also disordered. After viewing the UI hierarchy, it is found that ios11 used to directly add the button to the uinavigationbar, while ios11 first added the button to the UI navigation bar_ Uitamicadaptorview, added to_ UIButtonBarStackView、_ Uinavigationbarcontentview, followed by uinavigationbar. Therefore, if you need to obtain the navigation bar button frame or superview, you need to make special adaptation here

Hierarchical relationship diagram of navigation bar buttons in ios10 and below

Ios11 navigation bar button hierarchy diagram

3、 IPhone x adaptation

After downloading xcode9, the first thing is naturally to have fun on iPhone x (simulator), and then after compiling, you will find that there is an error

Because the status bar of iPhone x is quite different from other versions of mobile phones, the API changes greatly

The following adaptations have been made successively

Adaptation point 1: use the icon in the status bar to judge the specific status of the current network in the project


Error code

The printed log reports the following error: trapped uncaught exception ‘nsunknownkeyexception’, reason: ‘[< uistatus bar_modern 0x7fcdb0805770 > valueforundefined key:]: this class is not key value coding compliant for the key foregroundview.’

iPhone X

Other mobile phones

Using runtime to print all its properties, the following differences were found

//Test code
#import <objc/runtime.h>
NSMutableString *resultStr = [NSMutableString string];
//Gets the Ivar list and the number of Ivars of the specified class
unsigned int count = 0;
Ivar *member = class_copyIvarList([[application valueForKeyPath:@"_statusBar"] class], &count);
  
for(int i = 0; i < count; i++){
  Ivar var = member[i];
  //Gets the name of Ivar
  const char *memberAddress = ivar_getName(var);
  //Gets the type of Ivar
  const char *memberType = ivar_getTypeEncoding(var);
  NSString *str = [NSString stringWithFormat:@"key = %s       type = %s \n",memberAddress,memberType];
   [resultStr appendString:str];
}
NSLog(@"%@", resultStr);
//Other versions of mobile phones
key = _inProcessProvider      type = @"<UIStatusBarStateProvider>"
key = _showsForeground       type = B
key = _backgroundView        type = @"UIStatusBarBackgroundView"
key = _doubleHeightLabel      type = @"UILabel"
key = _doubleHeightLabelContainer  type = @"UIView"
key = _currentDoubleHeightText   type = @"NSString"
key = _ Currentrawdata type = {too long.}
key = _interruptedAnimationCompositeViews type = @"NSMutableArray"
key = _newStyleBackgroundView    type = @"UIStatusBarBackgroundView"
key = _newStyleForegroundView    type = @"UIStatusBarForegroundView"
key = _slidingStatusBar       type = @"UIStatusBar"
key = _styleAttributes       type = @"UIStatusBarStyleAttributes"
key = _waitingOnCallbackAfterChangingStyleOverridesLocally type = B
key = _suppressGlow         type = B
key = _translucentBackgroundAlpha  type = d
key = _showOnlyCenterItems     type = B
key = _foregroundViewShouldIgnoreStatusBarDataDuringAnimation type = B
key = _tintColor          type = @"UIColor"
key = _lastUsedBackgroundColor   type = @"UIColor"
key = _nextTintTransition      type = @"UIStatusBarStyleAnimationParameters"
key = _overrideHeight        type = @"NSNumber"
key = _disableRasterizationReasons type = @"NSMutableSet"
key = _timeHidden          type = B
key = _statusBarWindow       type = @"UIStatusBarWindow"

// iPhone X
key = _statusBar ; type = @"_UIStatusBar"

//Therefore, it can be seen that the status bar of iPhone x is nested one more layer and can be taken one more time. The final adaptation code is:
NSArray *children;
//It cannot be judged with [[self deviceversion] isequaltostring: @ "iPhone X"] because the simulator will not return iPhone X
  if ([[application valueForKeyPath:@"_statusBar"] isKindOfClass:NSClassFromString(@"UIStatusBar_Modern")]) {
    children = [[[[application valueForKeyPath:@"_statusBar"] valueForKeyPath:@"_statusBar"] valueForKeyPath:@"foregroundView"] subviews];
  } else {
    children = [[[application valueForKeyPath:@"_statusBar"] valueForKeyPath:@"foregroundView"] subviews];
  }

Adaptation point 2: after solving this problem, the project found that the height of the whole app interface was about 40pt

Old players who often download projects from GitHub know that some old projects will only have the layout space of iPhone 4 (320 * 480) after running on the simulator. The reason for this is that the corresponding image is not checked and set when the launch images source setting is used in the startup diagram. The solution is as follows

However, the larger pit of the iPhone x is the adaptation of the screen

First look at the screen size

This picture reflects a lot of information:

  • Although the width of iPhone x is the same as that of 7, it is 145pt higher
  • The use of triplicate is the key point, and it is generally believed that the highest screen density that can be recognized by the naked eye is 300ppi, and the iPhone X has reached 458ppi (it is verified that the screen density of Samsung Galaxy series is 522ppi)

In terms of design,Apple official document human interface guidelinesThere are clear requirements, which are described below in combination with the legend:

The displayed design layout is required to fill the whole screen

When filling, be careful that the control is not obscured by large rounded corners and sensor parts

Parts outside the security zone are not allowed to have any controls that interact with the user

The picture above contains a little more information

The head navigation bar does not allow user interaction, which means that Apple officially does not allow the following two cases

  • The virtual area at the bottom replaces the traditional home key, with a height of 34pt. Multi task management can be called by sliding up. Considering gesture conflict, this part is also not allowed to have any interactive controls
  • The status bar is in the non security area. It is also mentioned in the document that unless you can bring additional value to the user by hiding the status bar, it is best to return the status bar to the user

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support developpaer.

Recommended Today

JS generate guid method

JS generate guid method https://blog.csdn.net/Alive_tree/article/details/87942348 Globally unique identification(GUID) is an algorithm generatedBinaryCount Reg128 bitsNumber ofidentifier , GUID is mainly used in networks or systems with multiple nodes and computers. Ideally, any computational geometry computer cluster will not generate two identical guids, and the total number of guids is2^128In theory, it is difficult to make two […]