iOS11适配指南

作者: AKyS佐毅 | 来源:发表于2017-09-13 16:30 被阅读1965次
UIScrollViewContentInsetAdjustmentBehavior

使用第三方网络监测库报错

RealReachability 使用的PingFoundation 库报错

error

解决方式如下:替换成如下代码

__Check_Compile_Time(sizeof(ICMPHeader) == 8);
__Check_Compile_Time(offsetof(ICMPHeader, type) == 0);
__Check_Compile_Time(offsetof(ICMPHeader, code) == 1);
__Check_Compile_Time(offsetof(ICMPHeader, checksum) == 2);
__Check_Compile_Time(offsetof(ICMPHeader, identifier) == 4);
__Check_Compile_Time(offsetof(ICMPHeader, sequenceNumber) == 6);

UITableview UICollectionView MJRefresh下拉刷新错乱

UIScrollViewContentInsetAdjustmentBehavior

typedef NS_ENUM(NSInteger, UIScrollViewContentInsetAdjustmentBehavior) {
    UIScrollViewContentInsetAdjustmentAutomatic, // Similar to .scrollableAxes, but for backward compatibility will also adjust the top & bottom contentInset when the scroll view is owned by a view controller with automaticallyAdjustsScrollViewInsets = YES inside a navigation controller, regardless of whether the scroll view is scrollable
    UIScrollViewContentInsetAdjustmentScrollableAxes, // Edges for scrollable axes are adjusted (i.e., contentSize.width/height > frame.size.width/height or alwaysBounceHorizontal/Vertical = YES)
    UIScrollViewContentInsetAdjustmentNever, // contentInset is not adjusted
    UIScrollViewContentInsetAdjustmentAlways, // contentInset is always adjusted by the scroll view's safeAreaInsets
} API_AVAILABLE(ios(11.0),tvos(11.0));
  • automatic 和scrollableAxes一样,scrollView会自动计算和适应顶部和底部的内边距并且在scrollView 不可滚动时,也会设置内边距.

  • scrollableAxes 自动计算内边距.

  • never不计算内边距

  • always 根据safeAreaInsets 计算内边距

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

if (@available(iOS 11.0, *)) {
    self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
}

或者

#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)

tableView默认使用Self-Sizing

  • 这个配合estimatedRowHeight、estimatedSectionFooterHeight、estimatedSectionHeaderHeight使用,可以预估高度。之前,设置高度为0时,需要设置height=0.1,才会起作用,如果直接设置为0,则会使用默认高度,由于自动使用预估高度,所以,忽略了设置的高度,使原来的高度增大了。只要把这几个属性设置为0就可以解决。

相关文章

网友评论

  • 7f4bbad5097f:非常感谢,你帮我大忙了。
    AKyS佐毅:@大王加我来巡山 不客气
  • 444b305f7d35:没有测试ios11,上线被拒,遇到同样的问题,感谢楼主
    AKyS佐毅:@旧友_e94b 不客气!:grin:
  • 迟明子:感谢!!!! realreachability的适配问题就被你这样解决了!!!
    AKyS佐毅::joy: :joy: 不客气
  • koreadragon:关于RealReachability报错那个真是太恶心了,好在搜到了你的答案。特此谢过!
    AKyS佐毅: @koreadragon 不客气
  • Lius_:期待后续
    AKyS佐毅:@Lius_ 第一个问题,其实好解决。当收到推送,需要进行处理的时候,主动切换到主线程。第二个的话,需要自己调整位置:我现在在做,做完更新一个文章就可以了。 第三个问题 https://segmentfault.com/q/1010000010999970/a-1020000011001058 可以看这个。
    Lius_:倒入的小米推送和sharesdk总是提醒UI更新要在主线程 还有那个iPhoneX没有满屏 还有导航栏上的titleview也有问题 目前我只发现了这些
    AKyS佐毅:8 和8p上都没什么问题了。因为系统导航栏有很多问题,我们很早之前就每个界面都是自定义导航。所以导航的问题是不用解决的
  • iOS白水:导航 自定义左边item。之前设置间距失效了。这个有解决方案么?
    AKyS佐毅:http://www.jianshu.com/p/c0b359b801b3 这一篇可能对你有帮助

本文标题:iOS11适配指南

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