2016-09-14 69 views
1

我有一个包含4个单元的UICollectionView。 4个单元中的最后一个在屏幕的中间。如何以编程方式一直向右滚动,以便4个单元格中的第一个单元位于屏幕一半处?水平滚动一个UICollectionView一直到右/最后一个单元

我已经试过:

if (self.activeSection == .WISHES){ 
    cell.neighbourhoodHeaderCollectionView.setContentOffset(CGPointMake(CGFloat.max, 0), animated: false) 
} 

现在它是如何:

enter image description here

它需要如何:

enter image description here

+0

尝试使用'scrollToItem'([docs](https://developer.apple.com/reference/uikit/uicollectionview/1618046-scrolltoitem))而不是'setContentOffset' – spassas

+0

我试过了。不改变任何东西 –

回答

1

使用此...

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{ 
    return UIEdgeInsetsMake(0/*top*/, 5/*left*/, 0/*bottom*/, 5/*right*/); 
} 
+0

不改变任何东西为我的看法 –

+0

不,只有你设置右边和左边的边缘... – Rahul

+0

我试过了,但它仍然不适合我。 –

相关问题