美文网首页
iOS11 及 iPhone X出现的一些适配问题

iOS11 及 iPhone X出现的一些适配问题

作者: th先生 | 来源:发表于2017-10-11 11:47 被阅读0次

    1、scrollView (tableView) 向下偏移问题

    iOS 11遗弃了 automaticallyAdjustsScrollViewInsets 属性,在iOS 11之前,tableView跟navigationController搭配使用,会出现向下偏移64的问题,只需设置 self.automaticallyAdjustsScrollViewInsets = NO;即可。
    现在我们需要这样设置

     if (@available(iOS 11.0, *)) {
            if ([tableview respondsToSelector:@selector(setContentInsetAdjustmentBehavior:)]) {
                tableview.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
            }
        }else{
            self.automaticallyAdjustsScrollViewInsets = NO;
            
        }
    

    或者 重新设置tableView的contentInset值,来抵消掉SafeAreaInset值,因为内容下移偏移量 = contentInset + SafeAreaInset;
    如果之前自己设置了contentInset值为(64,0,0,0),现在系统又设置了SafeAreaInsets值为(64,0,0,0),那么tableView内容下移了64pt,这种情况下,可以设置contentInset值为(0,0,0,0),也就是遵从系统的设置了。


    又或者 通过设置iOS 11新增的属性addtionalSafeAreaInset;
    iOS 11之前,大家是通过将Controller的automaticallyAdjustsScrollViewInsets属性设置为NO,来禁止系统对tableView调整contentInsets的。如果还是想从Controller级别解决问题,那么可以通过设置Controller的additionalSafeAreaInsets属性,如果SafeAreaInset值为(20,0,0,0),那么设置additionalSafeAreaInsets属性值为(-20,0,0,0),则SafeAreaInsets不会对adjustedContentInset值产生影响,tableView内容不会显示异常。这里需要注意的是addtionalSafeAreaInset是Controller的属性,要知道SafeAreaInset的值是由哪个Controller引起的,可能是由自己的Controller调整的,可能是navigationController调整的。是由哪个Controller调整的,则设置哪个Controller的addtionalSafeAreaInset值来抵消掉SafeAreaInset值。


    若还想再VC层面进行禁用可以参考如下宏

    #define  adjustsScrollViewInsets(scrollView)\
    do {\
    _Pragma("clang diagnostic push")\
    _Pragma("clang diagnostic ignored \"-Warc-performSelector-leaks\"")\
    if ([scrollView respondsToSelector:NSSelectorFromString(@"setContentInsetAdjustmentBehavior:")]) {\
    NSMethodSignature *signature = [UIScrollView instanceMethodSignatureForSelector:@selector(setContentInsetAdjustmentBehavior:)];\
    NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature];\
    NSInteger argument = 2;\
    invocation.target = scrollView;\
    invocation.selector = @selector(setContentInsetAdjustmentBehavior:);\
    [invocation setArgument:&argument atIndex:2];\
    [invocation retainArguments];\
    [invocation invoke];\
    }\
    _Pragma("clang diagnostic pop")\
    } while (0)
    

    2、tableView cell间隔会拉大,或者sectionView高度变大

    tableView默认使用self-sizing,这个配合estimatedRowHeight,estimatedSectionFooterHeight,estimatedSectionHeaderHeight这三个属性一起使用,可以预估cell的高度。
    之前,你要想设置高度为0时,需要设置height=0.1,这样才会生效。
    现在我们需要这样设置,添加以下代码关闭估算行高

    if (@available(iOS 11.0, *)) {
            _TableView.estimatedRowHeight = 0;
            _TableView.estimatedSectionFooterHeight = 0;
            _TableView.estimatedSectionHeaderHeight = 0 ;
        }
    

    3、关于 Safe Area Layout Guide before iOS 9.0报错

    去掉右边 Use Safe Area Layout Guides对勾就行了

    屏幕快照 2017-10-11 上午11.06.39.png

    4、导航栏上面的searchBar消失

    iOS 11之前我们

    self.navigationItem.titleView =[ [UIView alloc] init];
    

    UIView上添加一个UISearchBar
    现在我们需要这样:

    #import "TUIView.h"
    @implementation TUIView
    
    -(CGSize)intrinsicContentSize{
             return UILayoutFittingExpandedSize;
    }
    @end
    

    然后在TUIView上添加UISearchBar

    5、[[UIScreen mainScreen] bounds].size不对,页面显示不能填充整个屏幕

    在运行iPhone X时,发现以前定义的屏幕size宏不对。原因在于此size取得是App启动时加载的启动图Size,只需在启动图在加入iPhone X尺寸的启动图即可,分辨率为1125*2436。

    如果没有横屏的需要可以去掉横屏启动图

    屏幕快照 2017-10-11 上午11.36.48.png

    6、关于iPhone X刘海

    之前状态栏statusbar高度20 navigationbar高度44 ==64
    现在 状态栏statusbar高度44 navigationbar高度44 == 88

    7、Xcode 9 打包时

    需要在icon的添加1024*1024的图标。

    8、command键复原

    可在Preferences --> Navigation -->Commadn-click 中选择Jumps to Defintion即可。

    相关文章

      网友评论

          本文标题:iOS11 及 iPhone X出现的一些适配问题

          本文链接:https://www.haomeiwen.com/subject/wigiyxtx.html