0

tableView から customCell をドラッグ アンド ドロップしようとしています。customCell の画像を取得してビューの周りにドラッグする UIImageView を使用していますが、customCell の画像を取得できないという問題があります。

CustomCellClass *customCell = [[CustomCellClass alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:[CustomCellClass identifier]];

customCell.textLabel.text = "Dragging cell";
_draggedImageView.image = customCell.imageRepresentation;

しかし、これは機能しません。イメージが得られません。

私も試しました:

 CustomCellClass *customCell = [tableView dequeueReusableCellWithIdentifier:[CustomCellClass identifier] forIndexPath:0];

customCell.textLabel.text = "Dragging cell";
_draggedImageView.image = customCell.imageRepresentation;

これは機能しますが、問題があります。再利用された customCell のテキストを変更しているので、tableView でも変更されます。customCell のコピーが必要なので、正しいレイアウトを作成し、そのコピーで必要なもの (この場合はセルの textLabel) を変更し、ドラッグする imageView を追加します。これは、tableView の customCell から分離されます。

これを達成する方法はありますか?

皆さん、ありがとうございました。

4

2 に答える 2

0

UIKit の -imageRepresentation の存在については知りません。通常、バッキング ストアからイメージを作成するには、ビットマップ コンテキストを作成し、そのコンテキスト内でビューをレンダリングして、最終的にイメージ表現を取得する必要があります。次のようなカテゴリを作成できます。

#import "UIView+RenderVIew.h"
#import <QuartzCore/QuartzCore.h>

@implementation UIView (RenderView)

- (UIImage *) imageByRenderingViewOpaque:(BOOL) yesOrNO {
    UIGraphicsBeginImageContextWithOptions(self.bounds.size, yesOrNO, 0);
    [self.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *resultingImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return resultingImage;
}
- (UIImage *) imageByRenderingView{
    return [self imageByRenderingViewOpaque:NO];
}

@end
于 2013-06-07T08:59:00.657 に答える
0

create aUIView Categoryでそれを行い、それにメソッドを追加し、任意のタイプの view( CustomCell) の画像が必要な場合は、この関数を呼び出します。その特定のビューの画像が返されます。

@implementation UIView (UIViewCategory)

- (UIImage*)convertInImage {

    UIGraphicsBeginImageContext(self.bounds.size);
    [self.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;
}
@end

使い方:

UIImage *cellImage = [yourCustomCellObj convertInImage];

私の場合は機能しています。問題が解決することを願っています。

于 2013-06-07T09:31:31.477 に答える