好吧,这是我现在常用的域,我已经管理了一些功能,但我需要让它变得更好。
我正在尝试从相机胶卷中填充最近的图像。我很确定有更优雅的方法可以做到这一点。让我不安的另一件事是,这是
Block > loop > another block
任何更好的解决方案或简化表示赞赏。
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);
}];
另外,我如何使图像进行延迟加载。我暂时禁用了分页,并且所有图像同时加载,这在大多数情况下是危险的。