0

I want to have a similar functionality as in the Photos app on the iPhone in my Scrollview. So I've added all images to my scrollview like this and it works nicely.

-(void)prepareScrollView
{
    for(int i =0;i<[self.layoverPhotoAssets count];i++){
        PHAsset *asset = self.layoverPhotoAssets[i];
        UIImageView *imageView = [[UIImageView alloc] init];
        int x = self.scrollView.frame.size.width * i;
        imageView.frame = CGRectMake(x, 0, self.scrollView.frame.size.width, self.scrollView.frame.size.height);
        imageView.contentMode = UIViewContentModeScaleAspectFit;

        PHImageRequestOptions *options = [[PHImageRequestOptions alloc] init];
        options.resizeMode = PHImageRequestOptionsResizeModeFast;
        options.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat; //I only want the highest possible quality
        options.synchronous = NO;
        options.networkAccessAllowed = YES;
        [[PHImageManager defaultManager] requestImageForAsset:asset targetSize:self.scrollView.frame.size contentMode:PHImageContentModeAspectFill options:options resultHandler:^(UIImage *result, NSDictionary *info) {
        dispatch_async(dispatch_get_main_queue(), ^{
            if(result){
                imageView.image = result;
            }
        });
        }];

        [self.scrollView setContentSize:CGSizeMake(self.scrollView.frame.size.width * (i + 1), self.scrollView.frame.size.height)];
        //self.scrollView.contentSize= ;
        [self.scrollView addSubview:imageView];
    }
}

However I have 2 questions: 1. Like this, all images will be loaded at once. Memory wise this is quite bad. How can I improve that without worsening the user experience? 2. How can I make the image itself zoomable?

MichiZH
  • 5,587
  • 12
  • 41
  • 81
  • A UICollectionView would be a good alternative. You can customized each thumbnail to follow the iOS 13 Photos app. You'll need to cache the image responses for smooth scroll performance. For zooming, when the image is tapped you can present the full image. – bbarnhart Jan 06 '20 at 22:15
  • Does this answer your question? [iOS Swift: How to recreate a Photos App UICollectionView Layout](https://stackoverflow.com/questions/44357103/ios-swift-how-to-recreate-a-photos-app-uicollectionview-layout) – bbarnhart Jan 06 '20 at 22:52
  • No this doesn't answer it.I am especially struggling with the whole swipeable gallery and how to cache stuff. I already have the whole collection view controller with the gallery etc. – MichiZH Jan 07 '20 at 20:24

0 Answers0