2013-10-24 38 views
0

我創建了一個圖像數組,並且它們以imageview開頭。用戶可以使用手勢拾取圖像,並將其拖放到單獨的圖像視圖中。他們可以來回移動他們,他們洗牌和組織自己,一切都很好。xcode查找UIImageview的內容

但我不知道哪些他們已經進入哪個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

要知道視圖附加的視圖,只需要查看屬性「superView」,以便在您的情況下如果想知道UIImageView中的視圖,則需要引用UIImageView像:

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

UIView *imageContainer = imageView.superView; 

如果指定一個標記,您的容器現在的你能做到這一點:

if (imageContainer.tag == aTag) { 

    Do something... 
} 
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;方法。