Adapter iOS 11

Determine the iOS 11 +
If (@available(iOS 11.0, *)) {}Copy the code
Safety zone

Starting with iOS 7, the topLayoutGuide and bottomLayoutGuide introduced in UIViewController were scrapped in iOS 11. In its place was the safeArea concept.

UITableView
  • The scrollbar jumps and pulls up and down to refresh

Self-sizing is enabled by default in iOS11, Headers, footers, and cells are enabled by default, All estimated height default value from 0 to change prior to the iOS11 UITableViewAutomaticDimension

In iOS11, self-sizing is enabled for tableView by default (Headers, footers, and cells are enabled by default, which was 0 before iOS11). If unrealized – tableView: viewForHeaderInSection: relating to the height of the agent method, the system will automatically set to the default height UITableViewAutomaticDimension. Solution:

/ / don't want to use the Self - under iOS11 Sizing, can through the following way closed Self. The tableView. EstimatedRowHeight = 0; self.tableView.estimatedSectionHeaderHeight = 0; self.tableView.estimatedSectionFooterHeight = 0;Copy the code

PS: With the introduction of self-sizing in iOS8, we can show dynamic content by implementing the estimatedRowHeight attribute, which gives us an initial contenSize estimate. This is obtained by estimatedRowHeight x cell number, which is not the final contenSize. The tableView no longer calculates the height of all the cells at once, but only calculates the number of cells that can be displayed on the current screen. The tableView keeps getting new cells, updating its own contenSize, and when it slides to the end, it gets the correct contenSize.

  • Layout, inside the secure area
self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 34, 0);
self.tableView.scrollIndicatorInsets =  UIEdgeInsetsMake(0, 0, 34, 0);
Copy the code
The search box

IOS 11 new attributes: navigationItem searchController navigationItem. HidesSearchBarWhenScrolling / / when the slide is to hide the search box To integrate UISearchController into Navigation, assign your UISearchController to navigationItem

Page migration

IOS11 deprecated automaticallyAdjustsScrollViewInsets properties, AutomaticallyAdjustsScrollViewInsets = NO is not set (the default is YES) so much at the top of the page is certain contentInset; Instead, the UIScrollView contentInsetAdjustmentBehavior attribute has been added

Therefore, all inherit from UIScrollView and its subclasses, all you need to set up global configuration contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever can:

If (@ the available (iOS 11.0, *)) { [[UIScrollView appearance] setContentInsetAdjustmentBehavior:UIScrollViewContentInsetAdjustmentNever]; } else { [UIScrollView appearance].contentInsetAdjustmentBehavior = NO; }Copy the code
  • Pull up system album to select a photo and move up the page
pickerControllder.navigationBar.translucent=NO;
Copy the code
Location permissions
< key > NSLocationUsageDescription < / key > < string > obtaining geographic location, accurate delivery service < / string > <! - during the use of access position - > < key > NSLocationWhenInUseUsageDescription < / key > < string > obtaining geographic location, accurate delivery service < / string > <! - always access the location - > < key > NSLocationAlwaysUsageDescription < / key > < string > App need your approval, can always access the location < / string > <! - the iOS 11 access - > < key > NSLocationAlwaysAndWhenInUseUsageDeion < / key > < string > App need your approval, can always access the location < / string >Copy the code
Album access permission
  • Save the picture

Add the privacy-Photo Library Additions Usage Description Key otherwise crash

TabBar position moving up during Push

Solution: Override pushViewController in the base class of UINavigationController to reset the TabBar frame for Push

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated { if (self.viewControllers.count >  0) { viewController.hidesBottomBarWhenPushed = YES; } [super pushViewController:viewController animated:animated]; / / modify CGRect frame = self. TabBarController. TabBar. Frame; frame.origin.y = [UIScreen mainScreen].bounds.size.height - frame.size.height; self.tabBarController.tabBar.frame = frame; }Copy the code

Iphones X

Screen size comparison

Status bar height, bottom safe distance

Landscape (Landscape)

  • The iPhone X:

StatusBar 20pt high, NavigationBar 44pt high, bottom TabBar 49pt high

  • The iPhone X:

StatusBar 44pt high, NavigationBar 44pt high, bottom TabBar 83pt high (due to safeArea added on iPhoneX)

Defining common macros
IPhoneX #define kScreenIphoneX [UIScreen mainScreen].bounds.size.height>=812 (kScreenIphoneX ? #define kStatusBarHeight (kScreenIphoneX? 44. F: 20.f) // Navigation bar Max y value #define kScreenIphoneX (kScreenIphoneX? 88.f : 64.f)Copy the code
NavBar new features

In iOS 11, the navigation bar is newlargeTitlesandsearchControllerTwo new features.

  • Set navigation bar largeTitles
self.navigationController? .navigationBar.prefersLargeTitles = YESCopy the code

NavigationItem. LargeTitleDisplayMode / / set the display time

Old engineering adaptation

Just add a LaunchImage with a size of 1125 × 2436 and use LaunchImage to load the LaunchImage instead of launchimage.storeborad

IOS12, iPhone XS Max, XR adaptation, Xcode10 configuration

Apple’s new product launch is over and ready to fill the hole

  • Start the figure

2. IPhone XS Max: 1242px x 2688px

The iPhone XS has the same screen size as the X, so it only needs video XR and XS Max.

If only the iPhone X startup image is set, the iPhone XR/XS Max will use the iPhone X startup image by default.

  • Judgment model

After X model, the bottom has a safe distance, so can use safeAreaInsets. Bottom > 0.0, to judge whether the iPhone X/XS/XR/XS Max.

1, the macro

#define isIPhoneXSeries ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? \ (\ CGSizeEqualToSize(CGSizeMake(375, 812),[UIScreen mainScreen].bounds.size)\ ||\ CGSizeEqualToSize(CGSizeMake(414, 896),[UIScreen mainScreen].bounds.size)\ )\ :\ NO)Copy the code

2. Inline functions

static inline BOOL isIPhoneXSeries() { BOOL iPhoneXSeries = NO; if (UIDevice.currentDevice.userInterfaceIdiom ! = UIUserInterfaceIdiomPhone) { return iPhoneXSeries; } if (@available(iOS 11.0, *)) {UIWindow *mainWindow = [[[UIApplication sharedApplication] delegate] window]; If (mainWindow. SafeAreaInsets. Bottom > 0.0) {iPhoneXSeries = YES; } } return iPhoneXSeries; }Copy the code
  • Xcode10 beta compilation issue

Libstdc++.6.0.9 and libstdc++ have been removed from Xcode10.

If you rely on libstdc++ in your project, either you use C++ to write your own functions cross-platform, or you introduce an SDK that relies on libstdc++ internally, the whole project will fail to compile, and Undefined symbols will be reported. The C++ List will not be found.

Libstdc++ was removed from XCode10 and iOS12, and replaced with libc++. Libstdc++ has been marked deprecated for 5 years, and libc++ is recommended to use the LLVM optimized libc++ library that fully supports C++11.

Solution: copy missing libstdc++ to

/Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/lib/ /Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/us r/lib/Copy the code

Remember to make two copies, one for the simulator and one for the device.