IOS11 has finally arrived, with some big changes to screen size and control features. The problem that looks on the net is scattered, 👇 collected the problem that appears in the development, sort out, use after convenient.






An overview of the directory

1. The navigation bar

The height of the navigation bar has always been fixed at 64P, but this rule has been broken in iOS11. In addition to iPhoneX full screen, bangs and other adaptation problems, titleView also added the property of the big title, supporting autolayout;





Headline example

// Set by prefersLargeTitles, default to NO; self.navigationController.navigationBar.prefersLargeTitles = YES;Copy the code

A comparison of the navigation bar is attached below:






Navigation bar size diagram for general models (except iPhoneX)






IPhoneX navigation bar size diagram

1.1 Size adaptation

Sol 1: macro definition height

#define NAVIGATION_HEIGHT (CGRectGetHeight([[UIApplication sharedApplication] statusBarFrame]) + CGRectGetHeight (self navigationController. NavigationBar. Frame)) # ifdef __IPHONE_11_0 if (@ the available (iOS 11.0, *)) { self.navigationBar.frame = CGRectMake(0, STATUSBAR_HEIGHT,ScreenWidth, NAVIGATION_HEIGHT); } #endifCopy the code

Sol 2: Obtain the height of a tool class

@implementation TestUtil + (CGFloat)navigationBarHeight {if (IS_iPhoneX) {return 88.0f; 64.0 f} return; } @end #define IS_iPhoneX ([UIScreen mainScreen].bounds.size.width == 375 && [UIScreen mainScreen].bounds.size.height == 812).Copy the code
1.2 titleView extension
/ / titleView since expanded size, need a custom view to implement this method (CGSize) intrinsicContentSize {return UILayoutFittingExpandedSize; }Copy the code
1.3 Return to button offset

Return button offset downward;

/ / set the navigationController backIndicatorImage and backIndicatorTransitionMaskImage UIImage * backButtonImage = [[UIImage imageNamed:@"icon_tabbar_back"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; self.navigationBar.backIndicatorImage = backButtonImage; self.navigationBar.backIndicatorTransitionMaskImage = backButtonImage;Copy the code

2. Security Area (Content)

About the safety area, tableView abandoned automaticallyAdjustsScrollViewInsets properties; estimatedRowHeight, EstimatedSectionHeaderHeight estimatedSectionFooterHeight three highly estimated by default 0 into UITableViewAutomaticDimension; Of course, this is where the UI gets messed up, and it’s worth mentioning the new tableView feature;

  • Set up thedelaysContentTouchesforNO, does not trigger the response event of the cell immediately.
  • Tap the cell with two fingers quickly to select both cells and enter the editing mode. If two fingers are out of sync, one of them is identified by default as a single cell.
  • A new property has been addedseparatorInsetReferenceYou can customize the margin of a cell line.
  • By default, the cell or table header and table tail use the adaptive height scheme (cause UI disorder).
  • The numberOfLines attribute was added to implement highly adaptive changes similar to UILabel;
2.1 Top Offset

AutomaticallyAdjustsScrollViewInsets attribute is rejected, the top is a little more migration; **sol 1: **

If (@ the available (iOS 11.0, *)) {self. TableView. ContentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; } else { self.automaticallyAdjustsScrollViewInsets = NO; }Copy the code

**sol 2: **

//iOS11 fixes SafeArea If (@available(iOS 11, *)) { [UIScrollView appearance].contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; }Copy the code

**sol 3: **

#define adjustsScrollViewInsets_NO(scrollView,vc)\do { \_Pragma("clang diagnostic push") \_Pragma("clang diagnostic ignored \"-Warc-performSelector-leaks\"") \if ([UIScrollView instancesRespondToSelector:NSSelectorFromString(@"setContentInsetAdjustmentBehavior:")]) {\[scrollView performSelector:NSSelectorFromString(@"setContentInsetAdjustmentBehavior:") withObject:@(2)]; \} else {\vc.automaticallyAdjustsScrollViewInsets = NO; \}\_Pragma("clang diagnostic pop") \} while (0)Copy the code

Users also appear webView will move down part of the distance problem;

If (@ the available (iOS 11.0, *)) { webView.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; } else { // Fallback on earlier versions }Copy the code
2.2 Cell spacing becomes larger

**sol 1: **

self.table.estimatedRowHeight = 0;
self.table.estimatedSectionHeaderHeight = 0;
self.table.estimatedSectionFooterHeight = 0;
Copy the code

**sol 2: **

// Fix iOS11, just implement heightForHeaderInSection, [UITableView appearance]. EstimatedRowHeight = 0; [UITableView appearance].estimatedSectionHeaderHeight = 0; [UITableView appearance].estimatedSectionFooterHeight = 0;Copy the code

3. Bottom area (tabBar)

The bottom area is mainly the iPhoneX is different from other models, the general model of 49 height, iPhoneX 83;

Adaptation problem
#define kTabBarHeight ([[UIApplication sharedApplication] statusBarFrame].size.height>20? 83:49)Copy the code

4. Other issues

In IOS11 original NSLocationAlwaysUsageDeion was downgraded to a NSLocationWhenInUseUsageDeion;

4.1 The dialog box for obtaining system permission is not displayed

Need to configure NSLocationAlwaysAndWhenInUseUsageDeion in the file, system box will pop up; Bounced using IOS11 requestAlwaysAuthorization obtain permission system will take several level listed, all for the user to choose from;

NSLocationUsageDescription obtaining geographic location, accurate delivery service NSLocationWhenInUseUsageDescription obtaining geographic location, Precision push service NSLocationAlwaysUsageDescription App need your approval, can always access the location NSLocationAlwaysAndWhenInUseUsageDeion App need your approval, can always access the locationCopy the code
4.2 iPhone X run buffer page has black area

Sol 1: Add the Launch image of iPhoneX 1125×2436. Use the LaunchScreen as the buffer page or modify the LaunchImage of Assets to add the Launch image of iPhoneX 1125×2436 (portrait screen).

Sol 2: Modify the Contents. Json file

{ "extent" : "full-screen", "idiom" : "iphone", "subtype" : "2436h", "filename" : PNG ", "minimum-system-version" : "11.0", "orientation" : "portrait", "scale" : "3x"}Copy the code

Sol 2: Use launchscreen.storyboard to position simple view constraints for various sizes of adaptation.

4.3 Third-party Dependent Libraries

ReactiveCocoa Unknown warning group ‘-wreceiver -is-weak’,ignored warning;

#define RACObserve(TARGET, KEYPATH) \
    ({ \
        _Pragma("clang diagnostic push") \
        _Pragma("clang diagnostic ignored \"-Wreceiver-is-weak\"") \
        __weak id target_ = (TARGET); \
        [target_ rac_valuesForKeyPath:@keypath(TARGET, KEYPATH) observer:self]; \
        _Pragma("clang diagnostic pop") \
    })
Copy the code
4.4 XIB Compilation Problems

Xib error: Warning: Internationalization is not available when compiling for targets before iOS 6.0 Select the xiB file with the compilation error and find Builds for iOS 7.0 and Later





4.5 Album Permission Change

IOS11 before: NSPhotoLibraryUsageDescription: visit albums and store photos to photo album (reading and writing), there will be a user authorization;

After iOS11: NSPhotoLibraryUsageDescription: do not need to add. Access to albums (read) is enabled by default, without user authorization; NSPhotoLibraryAddUsageDescription: add content to the album (write), there will be a user authorization;

These problems are the pit that the netizens wade through. I hope Jane friends can actively supplement and make progress together if they encounter other problems.

digression

A person’s National Day, waves do not rise, write a blog pressure alarm 😓

What we should know about iPhone X, iOS11, Xcode9 Are you surprised?” 5.8 Wry smile… IOS 11 adaptation navigation bar, tableView, searchBar bug Brief book App adaptation iOS11 10 minutes adaptation iOS11 & iPhone X iOS11 development new features complete iPhone X + iOS11 adaptation guide