こんにちは、Iphone フォト ライブラリを使用しています。AssetFramework を使用してフォト ライブラリからすべての写真を取得しました。それらの写真をスクロールビューで表示しましたが、完全に表示されており、画像数は6であると想定しています。次に、単一の画像をクリックすると、大きな画像が表示されます。それも行われます。私の問題は、「画像をクリックして大きく表示すると、カウントは12(ダブルカウント)です」です。
以下のコードを使用して画像を取得しました。
- (void)createScrollView
{
@try
{
NSLog(@"in create scrollview");
//add views to scrolview
// UIImageView *backgroundImgView;
int x=5;
int y=7;
NSLog(@"assetsArray/count/createScrollview %d",assetsArray.count);
for (int i=0;i<[assetsArray count];i++)
{
UIView *userView=[[UIView alloc] initWithFrame:CGRectMake(x, y, 70, 80)];
userView.tag=i;
UIImageView *backgroundImgView=[[UIImageView alloc] initWithFrame:CGRectMake(1, 1, 70, 70)];
backgroundImgView.tag=1;
// [backgroundImgView setImageWithURL:[NSURL URLWithString:[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF16BigEndianStringEncoding]] placeholderImage:[UIImage imageNamed:@"NoImage.png"]];
//-------------Getting Images from AssetsLibrary ----------
ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset)
{
galleryObj=[[GalleryObject alloc]init];
ALAssetRepresentation *rep = [myasset defaultRepresentation];
CGImageRef iref = [rep fullResolutionImage];
UIImage *assetsLibraryImage;
if (iref)
{
assetsLibraryImage = [UIImage imageWithCGImage:iref scale:[rep scale] orientation:(UIImageOrientation)[rep orientation]];
galleryObj.galleryImage=assetsLibraryImage;
}
else
{
assetsLibraryImage = [UIImage imageNamed:@"NoImage.png"];
}
//[set addObject:[NSString stringWithFormat:@"1"]];
[uniqueSet addObject:galleryObj];
NSLog(@"uniqueSet data is .....%@",uniqueSet); // Output (3,1,4,2,5) ... all objects
[imagesArray addObject:galleryObj];
NSLog(@"imagesArray/resultBlock count is %d array is %@....",imagesArray.count,imagesArray);
backgroundImgView.image=assetsLibraryImage;
};
ALAsset *al_asset = [assetsArray objectAtIndex:i];
//NSLog(@"al_asset is ......%@",al_asset);
al_assetUrl=al_asset.defaultRepresentation.url;
//NSLog(@"al_assetUrl is %@",al_assetUrl);
ALAssetsLibraryAccessFailureBlock failureblock = ^(NSError *myerror)
{
NSLog(@"ALAssetsLibraryAccessFailureBlock");
};
ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc] init];
[assetslibrary assetForURL:al_assetUrl resultBlock:resultblock failureBlock:failureblock];
//-------------Getting Images from AssetsLibrary ----------
UIButton *userButton=[[UIButton alloc]initWithFrame:CGRectMake(1, 1, 70,70)];
[userButton addTarget:self action:@selector(userImageClicked:) forControlEvents:UIControlEventTouchUpInside];
userButton.tag=i;
[userView addSubview:backgroundImgView];
[userView addSubview:userButton];
[self.galleryScrollview addSubview:userView];
x+=79;
if ((i+1)%4==0)
{
//if added image is 4th image
y+=80;
x=5;
}
// [activity stopAnimating];
}
if (y+100>self.galleryScrollview.frame.size.height)
{
self.galleryScrollview.contentSize=CGSizeMake(320, y+100);
}
else
{
self.galleryScrollview.contentSize=CGSizeMake(320, self.galleryScrollview.frame.size.height+60);
}
}
@catch (NSException *exception)
{
NSLog(@"exception is %@",exception);
}
}
ボタンを作成し、上記のメソッドでアクションが userImageClicked であることに注意してください。userImageClicked ボタンをクリックすると、配列の数が 2 倍になります。
なぜこれが起こったのかわかりません。containsObject メソッドを使用して重複を削除しようとしています。しかし、役に立たない。
上記の方法では、保存UIImage
しobjectclass
てそのオブジェクトを に割り当てましたimagesArray
。
値を保存するためにもNSMutableSet
使用しましたが、これも役に立ちません。
私の問題を解決するために誰かが提案してください。