下面的代码滚动到 UICollectionView
中的右侧单元格,但在我的例子中,部分标题 View 隐藏在 UINavigationBar
后面。我相信我应该使用 scrollRectToVisible
而我的问题是,当 numberOfRows
在给定的 section
是可变的。
- (void)scrollToPricing:(NSUInteger)row {
[self.collectionView scrollToItemAtIndexPath:
[NSIndexPath indexPathForItem:0
inSection:row]
atScrollPosition:UICollectionViewScrollPositionTop
animated:YES];
}
最佳答案
似乎所有的答案都过于复杂。这对我有用:
let attributes = self.collectionView.collectionViewLayout.layoutAttributesForSupplementaryViewOfKind(UICollectionElementKindSectionHeader, atIndexPath: NSIndexPath(forItem: 0, inSection: section))
self.collectionView.setContentOffset(CGPointMake(0, attributes!.frame.origin.y - self.collectionView.contentInset.top), animated: true)
swift 3:
if let attributes = collectionView.collectionViewLayout.layoutAttributesForSupplementaryView(ofKind: UICollectionElementKindSectionHeader, at: IndexPath(item: 0, section: section)) {
collectionView.setContentOffset(CGPoint(x: 0, y: attributes.frame.origin.y - collectionView.contentInset.top), animated: true)
}
关于ios - 将 UICollectionView 滚动到节标题 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22100227/