我需要当用户在水平布局CollectionView上滑动时,完成滑动后,所选单元格将设置在视图中心。
答案 0 :(得分:0)
需要做的事情:
ctor ()
{
CollectionView.Delegate = null; //Optionally
CollectionView.WillEndDragging += CollectionViewOnWillEndDragging;
}
private void CitiesCollectionViewOnWillEndDragging(object sender, WillEndDraggingEventArgs eventArgs)
{
eventArgs.TargetContentOffset = AdjustTargetContentOffset(eventArgs.TargetContentOffset);
}
private CGPoint AdjustTargetContentOffset(CGPoint eventArgs)
{
var countScrolledCells = (nint)(eventArgs.X / _cellWidth);
var offset = eventArgs.X % _cellWidth;
if (offset > _cellWidth / 2)
{
countScrolledCells++;
}
return new CGPoint(_cellWidth * countScrolledCells, 0);
}
或http://blog.karmadust.com/centered-paging-with-preview-cells-on-uicollectionview/