これが私のプロジェクトの仕組みです。UIScrollView下にはボタンがaddButtonあり、クリックするとリダイレクトされますAGImagePickerController(AGImagePickerControllerを知らない人にとっては、複数の画像ピッカーです)。次に、画像(単一または複数の画像)をクリックしました。を押すDONEと、画像が に保存されNSCachesDirectoryます。UIScrollView(削除可能)で選択した画像が表示されます。addButtonもう一度を押すpickedと、少し前の画像が で表示されますcheckMark。
問題:静止画UIScrollViewで削除された画像の画像を削除すると。で削除する場合は、 で削除する必要もあります。AGimagePickerControllercheckedUIScrollVIewAGimagePickerController
私がやりたかったのは、その画像を保存してから、簡単にロードできるようにURL内部のフォルダーに配置することですが、整数で名前を付けNSCachesDirectoryて画像を配置しているため、どこから始めればよいかわかりません。UIScrollView誰かが何をすべきかを提案してくれることを願っています。どうもありがとうございます。
注:これを読んだ人は、ここに投稿してほしいコードの部分、または問題がある部分についてコメントしてください。ありがとうございました。
コード:
これが私のDONE部分です:
for (int i = 0; i < info.count; i++) {
//NSLog(@"%@", [info objectAtIndex:i]);
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask ,YES );
NSString *documentsDir = [paths objectAtIndex:0];
NSString *savedImagePath = [documentsDir stringByAppendingPathComponent:[NSString stringWithFormat:@"oneSlotImages%u.png", i]];
ALAssetRepresentation *rep = [[info objectAtIndex: i] defaultRepresentation];
UIImage *image = [UIImage imageWithCGImage:[rep fullResolutionImage]];
//----resize the images
image = [self imageByScalingAndCroppingForSize:image toSize:CGSizeMake(256,256*image.size.height/image.size.width)];
//----fix image orientation
image = [image fixSlotOrientation];
NSData *imageData = UIImagePNGRepresentation(image);
[imageData writeToFile:savedImagePath atomically:YES];
}
それから私の中でAGIPCAssetsController.m(画像checkmark部分の保存場所)
- (void)loadAssets
{
count = 0;
[self.assets removeAllObjects];
AGIPCAssetsController *blockSelf = self;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
// Where I make an array to put the `ALAsset Url`
selectedPhotos = [[NSMutableArray alloc] initWithArray:blockSelf.imagePickerController.selection];
@autoreleasepool {
[blockSelf.assetsGroup enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) {
// ALAssetRepresentation* representation = [result defaultRepresentation];
// NSUInteger assetindex= [blockSelf.assetsGroup numberOfAssets];
if (result == nil)
{
return;
}
AGIPCGridItem *gridItem = [[AGIPCGridItem alloc] initWithAsset:result andDelegate:blockSelf];
if(count < blockSelf.imagePickerController.selection.count)
{
if ( blockSelf.imagePickerController.selection != nil &&
[result isEqual:[selectedPhotos objectAtIndex:count]])
{
gridItem.selected = YES;
count++;
NSLog(@" %@",result);
}
}
[blockSelf.assets addObject:gridItem];
}];
}
dispatch_async(dispatch_get_main_queue(), ^{
[blockSelf reloadData];
});
});
}