2010-10-26 17 views
17

के अंदर uiimageview में नल का पता लगाना मेरे पास इस तरह के कई UIImageViews के साथ एक UIScrollView है।uiscrollview

frame = [[UIImageView alloc] initWithImage:bg]; 
frame.frame = CGRectMake(FRAME_SEPARATOR + numPage*1024 + numColumn*(FRAME_SEPARATOR+230), 10 +numRow*(FRAME_SEPARATOR+145), 230, 145); 
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imageTapped:)]; 
[frame addGestureRecognizer:tap]; 
[tap release]; 
[scroll addSubView:frame]; 

समस्या यह है कि छवि पर टैप करते समय छवि टैप नहीं कहा जा रहा है।

अगर मैं इस तरह scrollview को इशारा पहचानकर्ता जोड़ें:

UITapGestureRecognizer *tap = 
[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imageTapped:)]; 
[scroll addGestureRecognizer:tap]; 
[tap release]; 

imageTapped कहा जाता है।

मैं UIImageViews पर नल का पता कैसे लगा सकता हूं?

धन्यवाद

उत्तर

46

सुनिश्चित करें userInteractionEnabled UIImageView पर हाँ पर सेट है:

frame.userInteractionEnabled = YES; 

मैं भी UIImageView चर के लिए एक अलग नाम का उपयोग की सलाह देते हैं (। उदाहरण के बजाय फ्रेम के imageView)। अन्यथा, आप आसानी से दृश्य की फ्रेम संपत्ति के साथ भ्रमित कर सकते हैं।

+0

धन्यवाद! इसने चाल बनाई। – Jorge

+0

+1 यह मेरी समस्या भी थी। धन्यवाद! – AWrightIV

+0

धन्यवाद, मुझे एक ही समस्या थी। – titaniumdecoy