2

これが私のプロジェクトの仕組みです。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];

        });

    }); 
}
4

2 に答える 2

1

両方とも同じ変数参照を持っていると思います。変数参照を確認し、両方を比較して、見つけたものを教えてください。

于 2012-10-08T13:11:13.933 に答える
1

単なるアイデアであり、正確な解決策ではありません。完了ボタンのアクションで、名前を付けて画像を の一意のプロパティとして保存することは可能ですかrep。の代わりに保存するときに、おそらく[rep filename]または[rep url]をイメージ名として使用できます@"oneSlotImages%u.png"。そして、loadAssetsキャッシュに保存されているすべての画像を読み取り、そのファイル名を画像のファイル名と比較し、キャッシュに存在しない場合は配列selectedPhotosから削除します。selectedPhotos

于 2012-10-10T07:11:07.767 に答える