嗯,這是我一貫域現在,我已經成功的一些功能,但我需要做的更好。在UIScrollView中填充圖像。而如何做到這一點懶洋洋地
我想從相機膠捲中填充最近的圖像。我很確定有更好的方法來做到這一點。 另一件讓我不安的事情是,這是
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);
}];
另外我該如何讓圖像做延遲加載。我現在禁用了分頁功能,並且所有圖像都是同時加載的,這在大多數情況下都是危險的。
http://stackoverflow.com/questions/9200597/trying-to-display-images-using-uiscrollview – 2013-05-19 09:06:55