0

我创建了一组图像,它们从图像视图开始。用户可以使用手势拾取图像并将它们拖放到单独的图像视图中。他们可以来回移动它们,它们可以自己洗牌和组织,一切都很好。

但我不知道他们移到了哪个图像视图中。如何识别哪个图像位于哪个图像视图中。我可以查询图像视图中的内容吗?

我查看了标签,但这并没有太大帮助。

我这样生成数组

NSArray *pngs = [NSArray arrayWithObjects:@"red", @"blue", @"green", @"yellow", @"purple", @"orange", @"black", @"white", nil];

  for (NSString *png in pngs) {
    UIImage *draggableImage = UIImageWithBundlePNG(png);
    UIImageView *draggableImageView = [[UIImageView alloc] initWithImage: draggableImage];
    SEDraggable *draggable = [[SEDraggable alloc] initWithImageView: draggableImageView];
    [self configureDraggableObject: draggable];

甚至不知道从哪里开始。

4

2 回答 2

1

尝试将标签添加到 UIImageView

  NSArray *pngs = [NSArray arrayWithObjects:@"red", @"blue", @"green",
 @"yellow",        @"purple", @"orange", @"black", @"white", nil];

for (NSString *png in pngs) {

UIImage *draggableImage = UIImageWithBundlePNG(png);

UIImageView *draggableImageView = [[UIImageView alloc] initWithImage: draggableImage];

draggableImageView.tag = i++;//i  must be initialized 

SEDraggable *draggable = [[SEDraggable alloc] initWithImageView: draggableImageView];

[self configureDraggableObject: draggable];

您可以通过 [imageView viewWithTag:TAG] 来识别 imageview;方法。

于 2013-10-24T10:53:22.450 回答
0

要知道附加视图时的视图,您只需查看属性“superView”,因此在您的情况下,如果想知道 UIImageView 内部的视图,您需要参考 UIImageView,例如:

UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bla"]];

UIView *imageContainer = imageView.superView;

如果您现在为容器分配标签,您可以这样做:

if (imageContainer.tag == aTag) {

    Do something...
}
于 2013-10-24T10:53:09.803 回答