With the release of Xcode GM, adapting to iOS 11 is on the agenda, but overall the process (excluding adapting to iPhone X) is not too troublesome.

Starting with Updating Your App for iOS 11, the WWDC Updating Your App for iOS 11 explains some of the API changes in iOS 11. It is helpful to understand the adaptation process.

navigation bar

1. There is a new big title style in the navigation bar. The default setting is not on, so there is no need to change it. 2. The titleView supports autolayout, which requires that the titleView must be self-supporting or implementable – intrinsicContentSize





search

The solution is simple: the view implementation corresponding to the search box – intrinsicContentSize method

- (CGSize)intrinsicContentSize {
    return UILayoutFittingExpandedSize;
}
Copy the code

Safety zone adaptation

11 of iOS ViewController automaticallyAdjustsScrollViewInsets attributes were abandoned, led to the two pages





image.png





image.png


Both of these pages hide the system navigation bar and customize the navigation bar.

self.automaticallyAdjustsScrollViewInsets = NO;
self.extendedLayoutIncludesOpaqueBars = YES;
self.edgesForExtendedLayout = UIRectEdgeTop;
Copy the code

AutomaticallyAdjustsScrollViewInsets properties were abandoned, the top is more an inset, adaptation of security area, Jane iOS this article 11 of the book safety area adaptation summary introduction is very detailed, please refer to the article.

We took a simpler approach

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

Navigation bar Return button





image.png


The previous code customizes the return button in the following way

UIImage *backButtonImage = [[UIImage imageNamed:@"icon_tabbar_back"]
    resizableImageWithCapInsets:UIEdgeInsetsMake(0, 18, 0, 0)];
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:backButtonImage
                                                  forState:UIControlStateNormal
                                                barMetrics:UIBarMetricsDefault];
[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60)
                                                     forBarMetrics:UIBarMetricsDefault];
Copy the code

11 of iOS setBackButtonTitlePositionAdjustment: UIOffsetMake can’t move the button a navigation bar. The solution is to set backIndicatorImage and backIndicatorTransitionMaskImage navigationController

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

Tableview problem





The correct style is on the right


If not implemented in iOS 11
-tableView: viewForFooterInSection:
-tableView: viewForHeaderInSection:, then
-tableView: heightForHeaderInSection:and
- tableView: heightForFooterInSection:Will not be called.


This is because
estimatedRowHeight
estimatedSectionHeaderHeight
estimatedSectionFooterHeightThe three height estimation attributes have been changed from the default 0
UITableViewAutomaticDimension, resulting in incorrect height calculation, the solution is to implement the corresponding method or set these three attributes to 0.


The following list shows not all of them
estimatedRowHeightError retrieving contentSize.






image.png

Third-party dependency library issues

1. ReactiveCocoa Unknown warning group ‘-wreceive-is-weak’,ignored warning





ReactiveCocoa


Simple book project started
Treat warning as errorAll warnings are treated as errors and must be resolved.



RACObserveMacros are defined as follows:

#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

In previous Xcode, the clang compiler would issue a receiver-IS-weak warning if the receiver was a weak object, so it added push&pop. The latest clang has removed this warning, so there is no need to add push&pop. ReactiveCocoa no longer maintains the OC version. Most OC developers use the 2.5 version and have to fork their own. However, the github v2.5 code does not contain the corresponding. Translate the corresponding JSON file into a. Podspec file on CocoaPods/Specs. If you want to do this, you can modify the Podfile as follows

Pod 'ReactiveCocoa' : git = > 'https://github.com/zhao0/ReactiveCocoa.git' : tag = > '2.5.2'Copy the code

MGSwipeTableCell crashes






The left slide cell


MGSwipeTableCell, which is used to implement the left swipe menu, crashed on iOS 11

Finally, thanks to my girlfriend for feeding me fruit while I write this article.