iOS UIScrollView滚动方法对比

项目中我们经常会使用到使视图滚动的方法,不管是collectionview或者是tableview最终都是使用以下方法

-(void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated;//以恒定速度动画到新偏移
-(void)scrollRectToVisible:(CGRect)rect animated:(BOOL)animated;//滚动使rect刚好可见(最近的边)。如果完全可见就什么都没有

但在某些系统下 -(void)scrollRectToVisible:(CGRect)rect animated:(BOOL)animated;方法滚动并不生效。

可以使用 -(void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated;方法替代。

//    这个方法在部分系统下不好使 有莫名其妙的问题 时好时不好
//    [self.contentCollectionView scrollRectToVisible:CGRectMake(indexPath.row*LL_ScreenWidth,self.contentCollectionView.frame.origin.y, self.contentCollectionView.frame.size.width, self.contentCollectionView.frame.size.height) animated:NO];
    
    [self.contentCollectionView setContentOffset:CGPointMake(toRow*LL_ScreenWidth, 0) animated:NO];
原文地址:https://www.cnblogs.com/lijianyi/p/13964046.html