对于 Xamarin.iOS 开发人员,我找到了这个解决方案:将 UIScrollView 元素添加到主视图并将 UICollectionView 添加为 UIScrollView 的元素。然后为 UIScrollView 创建一个缩放委托。
MainScrollView = new UIScrollView(new CGRect(View.Frame.X, View.Frame.Y, size.Width, size.Height));
_cellReuseId = GenCellReuseId();
_contentScroll = new UICollectionView(new CGRect(View.Frame.X, View.Frame.Y, size.Width, size.Height), new InfiniteScrollCollectionLayout(size.Width, size.Height));
_contentScroll.AllowsSelection = true;
_contentScroll.ReloadData();
_contentScroll.Center = MainScrollView.Center;
_contentScroll.Frame = new CGRect(_contentScroll.Frame.X, _contentScroll.Frame.Y - 32, _contentScroll.Frame.Width, _contentScroll.Frame.Height);
MainScrollView.ContentSize = _contentScroll.ContentSize;
MainScrollView.AddSubview(_contentScroll);
MainScrollView.MaximumZoomScale = 4f;
MainScrollView.MinimumZoomScale = 1f;
MainScrollView.BouncesZoom = true;
MainScrollView.ViewForZoomingInScrollView += (UIScrollView sv) =>
{
if (_contentScroll.Frame.Height < sv.Frame.Height && _contentScroll.Frame.Width < sv.Frame.Width)
{
_contentScroll.Center = MainScrollView.Center;
_contentScroll.Frame = new CGRect(_contentScroll.Frame.X, _contentScroll.Frame.Y - 64, _contentScroll.Frame.Width, _contentScroll.Frame.Height);
_contentScroll.BouncesZoom = true;
_contentScroll.AlwaysBounceHorizontal = false;
}
return _contentScroll;
};