여기 블록과 ALAssetLibrary 루틴으로 조금 고생하고 있습니다. 나는 WWDC + Stanford 동영상을 블록을 통해 읽었으며 조금 읽었지만 아직 나를 위해 클릭하지는 못했습니다.ALAssetsGroupAlbum의 posterImage를 앨범 이름으로 가져 오기
내가하려는 것은 커스텀 포토 라이브러리를위한 posterImage를 얻는 것이다. 아래의 첫 번째 루틴은 내 mainViewController에 있으며 ALAssetLibrary 클래스 확장에있는 getPosterImageForAlbum:
함수를 호출합니다.
/시도에 대해 내가/혼란과 어려움을 겪고 오전 일 :
내가 참조 (CGImageRef 나있는 UIImage)에 전달하고 ALAssetLibrary 방법을 설정하거나에 대한 반환 값을 정의해야 하는가를 ALAssetLibrary 메서드를 사용하고 메인 클래스의 이미지를 처리합니까? 나는 두 가지 방법으로 성공하지 못했습니다.
ALAssetLibrary 열거 형 메서드의 비동기 특성은 종류로 작동하기가 어려워서 잘못 처리 한 것 같습니다.
param으로 전달할 블록 정의 : 항상 typedef가 필요합니까?
나는 모든 개념적 비트와 조각들이 소용돌이 치고 있다고 생각하지만 블록으로 작업하는 것을 명확하게 이해하지 못했습니다. 좋은 기사에 대한 조언이나 조언 *은 많은 도움이 될 것입니다. //
- (IBAction)getPosterImage:(id)sender {
NSString *groupName = self.groupNameField.text;
NSLog(@"%@", groupName);
__weak typeof(self) weakSelf = self;
CGImageRef tmpImg = [weakSelf.library getPosterImageForAlbum:groupName withCompletionBlock:(CGImageRef)(^GetPosterImageCompletion)(NSError *error){
if (error!=nil) {
NSLog(@"getPosterImage error: %@", [error description]);
} else {
if (tmpImg != nil){
UIImage * posterImg = [UIImage imageWithCGImage:tmpImg];
weakSelf.pImage.image = posterImg;
}
}
}];
}
// 내가 게시 된 후에는 난 정말 당신이 무엇을 이해 않았기 때문에 이것은 내가 큰 방법으로 내 원래의 대답을 편집있어 ALAssetLibrary
typedef CGImageRef(^GetPosterImageCompletion)(NSError* error);
-(CGImageRef)getPosterImageForAlbum:(NSString*)albumName
withCompletionBlock:(GetPosterImageCompletion)completionBlock
{
__block BOOL albumWasFound = NO;
__block CGImageRef thePosterImage = nil;
SaveImageCompletion test;
//search all photo albums in the library
[self enumerateGroupsWithTypes:ALAssetsGroupAlbum
usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
NSLog(@"this group name: %@",
[group valueForProperty:ALAssetsGroupPropertyName]);
//compare the names of the albums
if ([albumName compare:
[group valueForProperty:ALAssetsGroupPropertyName]]==NSOrderedSame) {
printf("matches \n"); //target album is found
albumWasFound = YES;
thePosterImage = group.posterImage;
*stop = true;
return ;
}
} failureBlock: test];
if (albumWasFound==NO) {
NSLog(@"%@", @"No group found");
}
return thePosterImage;
}
시간을내어 주셔서 감사합니다! 나는 2 차 커피가 차고 난 후에이 코드를 씹어 야 할 것이다. 나는 코드 튜토리얼 코드로 시작했기 때문에 클래스 확장을 사용하고 있었다. (코드가 많은 길은 청소 된 코드로 포장되어있다.) –