美文网首页
scrollview自动适应导致真实位置上下偏移

scrollview自动适应导致真实位置上下偏移

作者: 与时间共舞 | 来源:发表于2018-06-05 09:49 被阅读0次

场景:

导航栏隐藏、通过View自定义导航栏。在一个ScollView中嵌套左右可以滑动的两个tabview列表,下拉刷新出现抖动等。

原因:

因为scrollview不能上下滑动的前提是
contensize.height==tabview.height。
而automaticallyAdjustsScrollViewInsets属性会导致scrollview的inset发生变化。
在iOS11以前的处理方法是
self.automaticallyAdjustsScrollViewInsets = NO;
但是,在iOS 11中automaticallyAdjustsScrollViewInsets属性被废弃了,self.automaticallyAdjustsScrollViewInsets = NO就等于没有设置(默认是YES),于是顶部就多了一定的contentInset的高度,导致视图发生偏移的现象。

解决办法:

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

相关文章

网友评论

      本文标题:scrollview自动适应导致真实位置上下偏移

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