iOS Developer

iOS11和iPhone X的适配

2017-09-22  本文已影响228人  大猿媛
导航

1、iOS 11 多了一个LargeTitleView,大字标题,导致导航栏达到了96p,默认关闭

2、UINavigationBar的结构和barbutton,titleView的左右边距有变化

3、UINavigationBar的子视图有改变,模态进去的导航要小心使用
3.1 iOS11之前的导航


屏幕快照 2017-09-26 下午1.56.40.png

3.2 iOS11之后的导航


屏幕快照 2017-09-26 下午1.57.36.png

3.3 iOS 11之后通过presentViewController进入的导航


屏幕快照 2017-09-26 下午1.58.41.png

开发需注意点:

列表

1、iOS11之前,scrollView不偏移64,就用automaticallyAdjustsScrollViewInsets = NO,而iOS11引入了

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

-automatic 和scrollableAxes一样,scrollView会自动计算和适应顶部和底部的内边距并且在scrollView 不可滚动时,也会设置内边距.
-scrollableAxes 自动计算内边距.
-never不计算内边距
-always 根据safeAreaInsets 计算内边距
// 大神代码:
#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)

或者

if (@available(iOS 11.0, *)) {
        canvas.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    } else {
        self.automaticallyAdjustsScrollViewInsets = NO;

2、heightForHeader和heightForFooter设置完不起作用,必须同时实现viewForHeader和viewForFooter方法

3、tableView滑动代码失效:scrollToRowAtIndexPath仍然有效

[self.tableView scrollRectToVisible:CGRectMake(0, 0, SCREENW, 20) animated:YES];
[self.tableView setContentOffset:CGPointMake(0, 20) animated:YES];

iOS11的scrollView的列表滑动或者滑动动画,以及截长屏都会失效,是由于iOS11默认开启了iOS8引入的self-sizing概念,默认进入并没有加载所有的元素,所以contentSize在起初进入加载完毕的时候是不对的,关闭的方法就是:

    self.tableView.estimatedRowHeight = 0;
    self.tableView.estimatedSectionHeaderHeight = 0;
    self.tableView.estimatedSectionFooterHeight = 0;

开发需注意:

2、由于phoneX的上下区域的特殊,引入的safeArea的概念,iOS11 cell的元素布局最好以cell.contentView作为参照去布局(横屏会有影响)

参考:https://www.lee1994.com/ios11ji-xcode9gua-pei-wen-ti-hui-zong/

上一篇 下一篇

猜你喜欢

热点阅读