Well this is my usual domain now, I have managed some functionality, but I need to make it better.
I am trying to populate recent images from camera roll. I'm pretty sure there is more elegant way to do it. Another thing thats making me uneasy is, this is
Block > loop > another block
Any better solution or simplification is appreciated.
ALAssetsLibrary *assetsLibrary = [[ALAssetsLibrary alloc] init];
[assetsLibrary enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos
usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
if (nil != group) {
[group setAssetsFilter:[ALAssetsFilter allPhotos]];
NSLog(@"%d images found", group.numberOfAssets);
for(int i = group.numberOfAssets - 5; i<group.numberOfAssets - 1; i++){
[group enumerateAssetsAtIndexes:[NSIndexSet indexSetWithIndex:i]
options:0
usingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) {
if (nil != result) {
ALAssetRepresentation *repr = [result defaultRepresentation];
UIImage *img = [UIImage imageWithCGImage:[repr fullResolutionImage]];
CGFloat aspectRatio = img.size.width/img.size.height;
UIImageView *imgView = [[UIImageView alloc] init];
imgView.frame = CGRectMake(10, self.yCord, 300, 300 /aspectRatio);
self.yCord += margin + (300/aspectRatio);
imgView.image = img;
imgView.layer.shadowRadius = 5.0;
imgView.layer.shadowColor = [UIColor blackColor].CGColor;
[self.scroll addSubview:imgView];
*stop = YES;
self.scrollViewHeight = self.yCord + imgView.frame.size.height + margin;
CGSize scrollViewSize = CGSizeMake(320, self.scrollViewHeight);
[self.scroll setContentSize:scrollViewSize];
}
}];}
}
*stop = NO;
} failureBlock:^(NSError *error) {
NSLog(@"error: %@", error);
}];
Also how do I make images do lazy load. I have paging disabled for now, and all the images load simultaneously, which is hazardous in most cases.