IOS11, iPhone X, Xcode9 adapter guide, ios11iphone

Source: Internet
Author: User
Tags home screen

IOS11, iPhone X, Xcode9 adapter guide, ios11iphone

After iOS11 is updated, it is found that adaptation is required in some areas. After sorting, the priority is divided into the following three categories:

1. changes caused by upgrade of iOS11;

2. changes caused by Xcode9 packaging;

3. Compatibility with iPhone x

I. changes caused by upgrade of iOS11

1. after the upgrade, you will find that the UI with tableView is disordered, and the group spacing and contentInset are disordered. Because the automaticallyAdjustsScrollViewInsets attribute of UIViewController in iOS11 is discarded, when tableView exceeds the safe area, the system automatically adjusts the SafeAreaInsets value to affect the adjustedContentInset value.

1 // some interfaces are set using the proxy method below, and the result is not valid 2-(CGFloat) tableView :( UITableView *) tableView heightForHeaderInSection :( NSInteger) section; 3-(CGFloat) tableView :( UITableView *) tableView heightForFooterInSection :( NSInteger) section; 4 // this principle is because a high proxy method was previously implemented, but not a View proxy method, there is no problem with iOS10 and the previous writing. iOS11 has enabled the bug caused by the high estimation mechanism. Therefore, there are several solutions: 5 // solution 1: add the View proxy method. Only the following two methods are implemented: method (CGFloat) tableView: heightForFooterInSection: takes effect 6-(UIView *) tableView :( UITableView *) tableView viewForFooterInSection :( NSInteger) section {7 return nil; 8} 9-(UIView *) tableView :( UITableView *) tableView viewForHeaderInSection :( NSInteger) section {10 return nil; 11} 12 // solution 2: directly use the tableView attribute to set the UI and fix the UI disorder 13 self. tableView. sectionHeaderHeight = 0; 14 self. tableView. sectionFooterHeight = 5; 15 [_ optionTableView setContentInset: UIEdgeInsetsMake (-35, 0, 0, 0)]; 16 // solution 3: Add the following code to close the estimation Row Height 17 self. tableView. estimatedRowHeight = 0; 18 self. tableView. estimatedSectionHeaderHeight = 0; 19 self. tableView. estimatedSectionFooterHeight = 0;

2. If Masonry is used for layout, safeArea must be adapted.

if ([UIDevice currentDevice].systemVersion.floatValue >= 11.0) {    make.edges.equalTo(self.view.safeAreaInsets);} else {    make.edges.equalTo(self.view);}

3. for the original image sending function of IM, iOS11 starts a new HEIC format image, and the live photo from iPhone 7 and above + iOS11 is ". heic "Format Image, same live Format Image, no problem when sending iOS10 (converted to jpg), iOS11 won't work

Is converted to jpg format

QQ and dingtalk are directly compressed, and even the source image is compressed as a non-source image.

The final solution is to convert the following code into jpg format:

// 0.83 ensures that the image size is consistent before and after compression // the cause of inconsistency is that the bitmap of the image is 8 bits, one is a 16-bit imageData = UIImageJPEGRepresentation ([UIImage imageWithData: imageData], 0.83 );

Ii. Problems found after Xcode9 Compilation

1. The third-party error "fastSocket" is found. The specific cause is that the header file C99 is missing. Just introduce "# include ".

2. New features in the navigation bar

The style of the native search bar has changed

The iOS11 style is displayed on the right. The search area height increases and the font size increases.

After checking the API, I found that the searchController is assigned to NavigationItem after iOS11, And the hidesSearchBarWhenScrolling attribute can be used to control whether the search bar is hidden and displayed when sliding.

// 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.@property (nonatomic) BOOL hidesSearchBarWhenScrolling API_AVAILABLE(ios(11.0)) API_UNAVAILABLE(tvos);

In addition, the BOOL value prefersLargeTitles of the UINavigationBar attribute is added to achieve the following effect. You can use largeTitleTextAttributes to set the text style of a large title. After setting the title, the height of the navigation bar will change from 64pt to 96pt. If there is an operation such as writing a dead height directly in the project or hiding the navigation bar, you need to adapt it.

A frame related to the buttons in the navigation bar is used on the UI, and UI disorder occurs. After you view the UI hierarchy, you can find that the buttons were directly added to the UINavigationBar before iOS11, iOS11 adds the button to _ UITAMICAdaptorView first, then _ UIButtonBarStackView, _ UINavigationBarContentView, and then UINavigationBar. Therefore, if you need to obtain the navigation bar button frame or superView, here you need to make specific adaptation

Hierarchical relationship diagram of buttons in iOS10 and earlier versions of the navigation bar

Hierarchical relationship diagram of buttons in the iOS11 navigation bar

3. iPhone X adaptation

After Xcode9 is downloaded, the first thing to do is to enjoy it on the iPhone X (simulator). After compilation, an error is reported.

The Status Bar of iPhone X differs greatly from that of other mobile phones, so the api changes a lot.

The following adaption has been made successively:

Adaption Point 1: Use the icon in the status bar in the project to determine the specific status of the current network

Error Code

1 The printed Log reports the following error: Trapped uncaught exception'NSUnknownKeyException', reason: '[ valueForUndefinedKey:]: this class is not key value coding-compliant for the key foregroundView.'

IPhone X

Other mobile phones

Use runtime to print all its attributes and find the following differences:

// Test code # import NSMutableString * resultStr = [NSMutableString string]; // obtain the Ivar list of the specified class and the number of Ivar unsigned int count = 0; ivar * member = class_copyIvarList ([application valueForKeyPath: @ "_ statusBar"] class], & count); for (int I = 0; I <count; I ++) {Ivar var = member [I]; // obtain the Ivar name const char * memberAddress = ivar_getName (var ); // obtain the Ivar type const char * memberType = ivar_getTypeEncoding (var); NSString * str = [NSString stringWithFormat: @ "key = % s type = % s \ n", memberAddress, memberType]; [resultStr appendString: str];} NSLog (@ "% @", resultStr ); // key = _ inProcessProvider type = @ "" key = _ showsForeground type = Bkey = _ backgroundView type = @ "UIStatusBarBackgroundView" key = _ doubleHeightLabel type = @ "UILabel "key = _ doubleHeightLabelContainer type = @" UIView "key = _ currentDoubleHeightText type = @" N SString "key = _ currentRawData type = {very long ..} Key = _ primitive type = @ "NSMutableArray" key = _ newStyleBackgroundView type = @ "partition" key = _ newStyleForegroundView type = @ "partition" key = _ slidingStatusBar type = @ "UIStatusBar" key = _ styleAttributes type = @ "external" key = _ external type = Bkey = _ suppressGlow type = Bkey = _ translucentBackgroundAlpha type = dkey = _ showOnlyCenterItems type = Bkey = _ external type = bkey = _ tintColor type = @ "UIColor" key = _ lastUsedBackgroundColor type = @ "UIColor" key = _ nextTintTransition type = @ "identifier" key = _ overrideHeight type = @ "NSNumber" key = _ disableRasterizationReasons type = @ "NSMutableSet" key = _ timeHidden type = Bkey = _ statusBarWindow type = @ "UIStatusBarWindow" // iPhone Xkey = _ statusBar; type = @ "_ UIStatusBar" // Therefore, the status bar of the iPhone X is nested with one layer. You can obtain the status bar once more. The final adaptation code is: NSArray * children; // The [[self deviceVersion] isw.tostring: @ "iPhone X"] cannot be used for determination, because the iPhone X simulator does not return the 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];}

Warning the above processing, the Code does not seem to report an error, however !! The Code does not take effect! Because only view-level information is obtained from the iPhone X, the following method is used to determine 2G/3G/4G. This method is effective in API visual testing.

NSArray * typeStrings2G = @ [metrics, CTRadioAccessTechnologyGPRS, metrics]; NSArray * typeStrings3G = @ [metrics, CTRadioAccessTechnologyWCDMA, metrics]; NSArray * typeStrings4G =@ [CTRadioAccessTechnologyLTE]; // This API is valid for systems above iOS7 ([[UIDevice currentDevice] systemVersion] floatValue]> = 7.0) {CTTelephonyNetworkInfo * teleInfo = [[CTTelephonyNetworkInfo alloc] init]; NSString * accessString = teleInfo. currentRadioAccessTechnology; if ([typeStrings4G insobject: accessString]) {NSLog (@ "4G 4G 4G");} else if ([typeStrings3G containsObject: accessString]) {NSLog (@ "3G network");} else if ([typeStrings2G containsObject: accessString]) {NSLog (@ "2G network ");} else {NSLog (@ "Unknown network") ;}} else {NSLog (@ "Unknown network ");}

Adaptation Point 2: After this problem is solved, The project runs up and finds that the entire app interface has a height of approximately 40 PT

Download the project from Github frequently. The old drivers know that some old projects only have the layout space of iPhone 4 (320480) after running on the simulator, the reason for this is that when the Launch graph is set using Launch Images Source, the corresponding image (11252436) is not checked and set. The solution is as follows:

However, even after performing the preceding operations, you will find that the UITabBar at the bottom is still a little higher. After you view the hierarchy, you will find that the UITabBar height is changed from 49pt to 83pt due to the security zone, therefore, we need to adapt the iPhone X and Its simulator here.

Adaptation Point 3: iPhone X only has faceID and no touchID. If the in application uses the touchID to unlock, the model must be adapted here.

Adaptation Point 4: Previously, the status bar height was replaced by 20, which must be re-obtained by the status bar height.

CGRectGetHeight([UIApplication sharedApplication].statusBarFrame)

Adaptation Point 5: However, the bigger pitfall of iPhone X is screen adaptation.

First, check the screen size.

This figure shows a lot of information:

Although the width of iPhone X is the same as that of 7, the height is 145pt

Three times the image is the focus, and the highest screen density that can be identified by the naked eye is generally considered to be 300ppi, and the iPhone X has reached 458ppi (the Samsung galaxy series screen density is found to be 522ppi)

In terms of design, the apple Official Document "human-interface-guidelines" has clear requirements. The following is a description based on the legend:

The displayed design layout requires filling up the entire Screen

When filling up, be sure not to hide the control from the large rounded corner and the sensor part.

Controls other than security zones cannot interact with users.

The figure above contains a little more information.

The header navigation bar does not allow user interaction, which means that the following two cases are not officially allowed by Apple.

The virtual area at the bottom replaces the traditional home key with a height of 34pt. by sliding up, you can call multiple task management. Considering gesture conflicts, this part is not allowed to have any interactive controls, however, the designed background image must cover non-secure areas.

The status bar is in a non-secure area, which is also mentioned in this document. Unless you can hide the status bar to bring additional value to the user, it is best to return the status bar to the user.

Do not disturb elements in the interface with the home screen indicator at the bottom

Pay attention to the aspect ratio difference when reusing existing images. The aspect ratio of the iPhone X screen is different from that of the conventional iPhone. Therefore, the full-screen 4.7-inch screen image will show cropping or adaptive width display on the iPhone X screen. Therefore, this part of the view needs to be adapted according to the device.

Note the bitmap adaptation.

Adaptation Point 6: horizontal screen adaptation

For safe area, using safeAreaLayoutGuide and safeAreaInset can solve most problems, but there may be some problems in the horizontal screen, and additional adaptation is required.

The code for this reason is: [headerView. contentView setBackgroundColor: [UIColor headerFooterColor]. This method looks correct, but there is only a problem with iPhone X.

By setting this attribute, the content view is embedded into the safe area, but the contentView does not

Solution: Set the backgroundView color [headerView. backgroundView setBackgroundColor: [UIColor headerFooterColor]

Adaptation Point 7: device information

If ([deviceString is tostring: @ "iPhone10, 1"]) return @ "(A1863), A1906) iPhone 8"; if ([deviceString is tostring: @ "iPhone10, 4 "]) return @" US edition (Global/A1905) iPhone 8 "; if ([deviceString isEqualToString: @" iPhone10, 2 "]) return @" (A1864) and A1898 iPhone 8 Plus "; if ([deviceString isw.tostring: @" iPhone10, 5 "]) return @" US edition (Global/A1897) iPhone 8 Plus "; if ([deviceString is tostring: @ "iPhone10, 3"]) return @ "Guo Xing (A1865), nixing (A1902) iPhone X"; if ([deviceString isEqualToString: @ "iPhone10, 6 "]) return @" US edition (Global/A1901) iPhone X ";

 

Related Article

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.