我创建了一个图像数组,它们从imageview开始。用户可以使用手势拾取图像并将其拖放到单独的图像视图中。他们可以来回移动他们,他们洗牌和组织自己,一切都很顺利。
但我不知道他们在哪个imageview中进入了哪个。如何识别哪个图像存在于哪个imageview中。我可以查询imageview中的内容吗?
我查看了标签,这没什么用。
我生成数组
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];
不确定从哪里开始。
答案 0 :(得分: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]识别图像视图;方法
答案 1 :(得分:0)
要了解附加视图时的视图,您只需查看属性'superView',所以在您的情况下如果想知道UIImageView内部的视图,您需要引用UIImageView之类的:
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bla"]];
UIView *imageContainer = imageView.superView;
如果您现在可以为容器分配标签:
if (imageContainer.tag == aTag) {
Do something...
}