2010-02-18 158 views
1

我該如何對其進行編碼,以便它能夠檢測到哪個圖像被首先點擊?換句話說,如果其中一個被挖掘,但另一個已經隱藏起來,我想讓它發揮不同的聲音?有任何想法嗎?touchesBegan在iPhone SDK中的問題?

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    UITouch *touch = [touches anyObject]; 
    NSLog(@"tag %@",touch); 
    if([touch view] == test) { 
     test.hidden=YES; 
     [self playpopsound]; 
    } 
    else if([touch view] == test2){ 
     test2.hidden=YES; 
     [self playpopsound]; 
    } 
} 

回答

3

每個UIView可以具有與其相關聯的唯一tag,這僅僅是一個無符號整數。您可以比較視圖標籤以快速測試其等效性。