自定义滚动条

2018-05-17  本文已影响8人  iOSCoder

计算其滑动距离

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    
    if ([self.collectionView isEqual:scrollView]) {
        
        //计算偏移量
        CGFloat offsetX = self.collectionView.contentOffset.x;
        
        //150----滚动条的总长度
        CGFloat X = offsetX*(150-self.line.frame.size.width)/(self.collectionView.contentSize.width-self.collectionView.frame.size.width);
        [self.line mas_updateConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(X);
        }];
        
        [self.line.superview layoutIfNeeded];
    }
}
上一篇 下一篇

猜你喜欢

热点阅读