selector

iOS开发之iOS11适配问题

2017-12-07  本文已影响207人  a6750108cb56

`## 1.tableView的适配

  1. 导航栏向上跑了部分距离:宏定义一个高度
    参见第6条
  2. VC中的tableView向下移动部分距离,以及cell直接的间隔会无故拉大:在你的tableView下面添加这句话
if (@available(iOS 11.0, *)) {

UIScrollView.appearance.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;

} else {

// Fallback on earlier versions

}
  1. 如果你的cell 之间的间距拉大,就在self.xf_tableView.contentInset = UIEdgeInsetsMake(64, 0, 0, 0);这个约束后面添加下面三个约束
self.xf_tableView.estimatedRowHeight = 0;

self.xf_tableView.estimatedSectionHeaderHeight = 0;

self.xf_tableView.estimatedSectionFooterHeight = 0;
  1. 加载webView的时候会向下移动部分距离:给你的web添加下面约束
if (@available(iOS 11.0, *)) {

webView.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;

} else {

// Fallback on earlier versions

}
  1. 创建搜索框
UIView *titleView = [[TUIView alloc] init];

titleView.py_x = PYSEARCH_MARGIN * 0.5;

titleView.py_y = 7;

titleView.py_width = self.view.py_width - 64 - titleView.py_x * 2;

titleView.py_height = 30;

UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:titleView.bounds];

[titleView addSubview:searchBar];

self.navigationItem.titleView = titleView;  
  1. 升级Xcode 9 + iOS 11后,发现原本没问题的collectionView和tableView像是中了风一样,头部刷新UI出现了错乱。
    查阅发现 iOS11弃用了automaticallyAdjustsScrollViewInsets属性,新增contentInsetAdjustmentBehavior来替代它
    关于 contentInsetAdjustmentBehavior
@available(iOS 11.0, *)
public enum UIScrollViewContentInsetAdjustmentBehavior : Int {

    case automatic // Similar to .scrollableAxes, but will also adjust the top & bottom contentInset when the scroll view is owned by a view controller with automaticallyAdjustsScrollViewContentInset = YES inside a navigation controller, regardless of whether the scroll view is scrollable

    case scrollableAxes // Edges for scrollable axes are adjusted (i.e., contentSize.width/height > frame.size.width/height or alwaysBounceHorizontal/Vertical = YES)

    case never // contentInset is not adjusted

    case always // contentInset is always adjusted by the scroll view's safeAreaInsets
}

UIScrollViewContentInsetAdjustmentBehavior 是一个枚举类型,值有以下几种:

* -automatic 和scrollableAxes一样,scrollView会自动计算和适应顶部和底部的内边距并且在scrollView 不可滚动时,也会设置内边距.
* -scrollableAxes 自动计算内边距.
* -never不计算内边距
* -always 根据safeAreaInsets 计算内边距

很显然,我们这里要设置为 never

        //声明tableView的位置 添加下面代码
        if (@available(iOS 11.0, *)) {
            _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
            _tableView.contentInset = UIEdgeInsetsMake(64, 0, 49, 0);
            _tableView.scrollIndicatorInsets = _tableView.contentInset;
        }

2.iOS11之后,跳转App Store

 NSString *appstoreUrlString = [NSString stringWithFormat: @"itms-apps://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=%@",AppStoreAppId ];
NSURL * url = [NSURL URLWithString:appstoreUrlString];
if ([[UIApplication sharedApplication] canOpenURL:url]){
        [[UIApplication sharedApplication]openURL:url];
 }else{
        WKLog(@"can not open");
}

需要改成

NSString *appstoreUrlString = [NSString stringWithFormat:@"itms-apps://itunes.apple.com/cn/app/idXXXXXX?mt=8&action=write-review", AppStoreAppId ];
NSURL * url = [NSURL URLWithString:appstoreUrlString];
if ([[UIApplication sharedApplication] canOpenURL:url]){
                    [[UIApplication sharedApplication]openURL:url];
 }else{
        WKLog(@"can not open");
}

3.iPhoneX的适配

需要一张 1125 *2436 的图片加入启动页LaunchImage。

4.可以使用NFCiOS11新特性 - Core NFC

5.asset新特性

6.根据Navigation、Tabbar的高度宏定义

#define ScreenWidth [[UIScreen mainScreen] bounds].size.width
#define ScreenHeight [[UIScreen mainScreen] bounds].size.height
#define Is_Iphone (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
#define Is_Iphone_X (Is_Iphone && ScreenHeight == 812.0)
#define NaviHeight Is_Iphone_X ? 88 : 64
#define TabbarHeight Is_Iphone_X ? 83 : 49
#define BottomHeight Is_Iphone_X ? 34 : 0

7.UIKit框架

8.开发建议

参考资料:

上一篇 下一篇

猜你喜欢

热点阅读