uiscrolView基本使用

拖拽和非拖拽滚动时滚动结束方法:

非拖拽

scrollViewDidEndScrollingAnimation

拖拽

scrollViewDidEndDecelerating

侧滑冲突

TZScrollViewPopGesture

[self tz_addPopGestureToView:_bgScrolView];

禁止滚动

scrollView.contentSize(width,0);

自动左右偏移

if (_page>=6) {
                [_topScrolView setContentOffset:CGPointMake(100*wzoom*(_page-6), 0) animated:YES];
            }

1.不显示滚动条

scrollView.showsVerticalScrollIndicator = FALSE;//竖直

scrollView.showsHorizontalScrollIndicator = FALSE;//水平

2、偏移适配

相信对于iOS11的适配大家都应该不陌生,都是老生常谈的一些问题,其中在iOS11适配中关于UIScrollView的contentInsetAdjustmentBehavior属性, 这个属性的内部结构:
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));

1.UIScrollViewContentInsetAdjustmentAutomatic (类似于UIScrollViewContentInsetAdjustmentScrollableAxes,scrollView会自动计算和适应顶部和底部的内边距,并且在scrollView不可滚动时,也会设置内边距)
2.UIScrollViewContentInsetAdjustmentScrollableAxes (自动计算内边距)
3.UIScrollViewContentInsetAdjustmentNever (不计算内边距)
4.UIScrollViewContentInsetAdjustmentAlways (根据safeAreaInsets计算内边距)

处理方式:为了适配iOS11,我们需要把这个属性禁用调,使用UIScrollViewContentInsetAdjustmentNever不计算内边距,不然系统会帮我们自动计算内边距,这样在滚动之后无法定位,会出现额外的内边距偏差。
简化处理:之前项目内有大量的UIScrollView,UITableView和UICollectionVIew中单独处理iOS11的适配,导致大量的重复代码,其实没必要每次初始化的时候去单独处理这个属性,这几个控件都是遵循appearance,我们可以进行全局统一设置来简化代码。
- (void)adapterIOS11{
    // 适配iOS11以上UITableview 、UICollectionView、UIScrollview 列表/页面偏移
    if (@available(iOS 11.0, *)){
        [[UIScrollView appearance] setContentInsetAdjustmentBehavior:UIScrollViewContentInsetAdjustmentNever];

        [[UITableView appearance] setEstimatedRowHeight:0];
        [[UITableView appearance] setEstimatedSectionFooterHeight:0];
        [[UITableView appearance] setEstimatedSectionHeaderHeight:0];
    }
}

然后在AppDelegate启动项目时,调用该方法,在didFinishLaunchingWithOptions中就能够完美的实现iOS11内边距偏移的适配。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值