コード例 #1
0
        void UpdateCachedAssets()
        {
            bool isViewVisible = IsViewLoaded && View.Window != null;

            if (!isViewVisible)
            {
                return;
            }

            // The preheat window is twice the height of the visible rect.
            CGRect preheatRect = CollectionView.Bounds;

            preheatRect = preheatRect.Inset(0f, -.5f * preheatRect.Height);

            nfloat delta = NMath.Abs(preheatRect.GetMidY() - previousPreheatRect.GetMidY());

            if (delta > CollectionView.Bounds.Height / 3.0f)
            {
                // Compute the assets to start caching and to stop caching.
                var addedIndexPaths   = new List <NSIndexPath> ();
                var removedIndexPaths = new List <NSIndexPath> ();

                ComputeDifferenceBetweenRect(previousPreheatRect, preheatRect, removedRect => {
                    var indexPaths = CollectionView.GetIndexPaths(removedRect);
                    if (indexPaths != null)
                    {
                        removedIndexPaths.AddRange(indexPaths);
                    }
                }, addedRect => {
                    var indexPaths = CollectionView.GetIndexPaths(addedRect);
                    if (indexPaths != null)
                    {
                        addedIndexPaths.AddRange(indexPaths);
                    }
                });

                var assetsToStartCaching = AssetsAtIndexPaths(addedIndexPaths.ToArray());
                var assetsToStopCaching  = AssetsAtIndexPaths(removedIndexPaths.ToArray());

                // Update the assets the PHCachingImageManager is caching.
                if (assetsToStartCaching != null)
                {
                    imageManager.StartCaching(assetsToStartCaching, assetGridThumbnailSize, PHImageContentMode.AspectFill, null);
                }
                if (assetsToStopCaching != null)
                {
                    imageManager.StopCaching(assetsToStopCaching, assetGridThumbnailSize, PHImageContentMode.AspectFill, null);
                }

                // Store the preheat rect to compare against in the future.
                previousPreheatRect = preheatRect;
            }
        }
コード例 #2
0
        void UpdateCachedAssets()
        {
            bool isViewVisible = IsViewLoaded && View.Window != null;

            if (!isViewVisible)
            {
                return;
            }

            // The preheat window is twice the height of the visible rect.
            CGRect preheatRect = CollectionView.Bounds;

            preheatRect = preheatRect.Inset(0, -preheatRect.Height / 2);

            // Update only if the visible area is significantly different from the last preheated area.
            nfloat delta = NMath.Abs(preheatRect.GetMidY() - previousPreheatRect.GetMidY());

            if (delta <= CollectionView.Bounds.Height / 3)
            {
                return;
            }

            // Compute the assets to start caching and to stop caching.
            var rects       = ComputeDifferenceBetweenRect(previousPreheatRect, preheatRect);
            var addedAssets = rects.Added
                              .SelectMany(rect => CollectionView.GetIndexPaths(rect))
                              .Select(indexPath => FetchResult.ObjectAt(indexPath.Item))
                              .Cast <PHAsset> ()
                              .ToArray();

            var removedAssets = rects.Removed
                                .SelectMany(rect => CollectionView.GetIndexPaths(rect))
                                .Select(indexPath => FetchResult.ObjectAt(indexPath.Item))
                                .Cast <PHAsset> ()
                                .ToArray();

            // Update the assets the PHCachingImageManager is caching.
            imageManager.StartCaching(addedAssets, thumbnailSize, PHImageContentMode.AspectFill, null);
            imageManager.StopCaching(removedAssets, thumbnailSize, PHImageContentMode.AspectFill, null);

            // Store the preheat rect to compare against in the future.
            previousPreheatRect = preheatRect;
        }