ios - Detecting individual touches on Multiple UIImageviews? -


i have added around 15 16 uiimageviews on view using following code

- (void) setupcellsusingimage: (uiimage *) masterimage {   rows = 4;  cols = 4;  containercellheight=hight/4; containercellwidth=width/4;    nsinteger row, col; cgimageref tempsubimage; cgrect temprect; cgfloat ypos, xpos;   uiimage * auiimage; uiimageview *label;  cellarray = [[nsmutablearray new] autorelease]; int =0;  (row=0; row < rows; row++) {     ypos = row * containercellheight;     (col=0; col < cols; col++) {         xpos = col * containercellwidth;         label = [[uiimageview alloc]init];         temprect = cgrectmake(xpos, ypos, containercellwidth, containercellheight);               tempsubimage = cgimagecreatewithimageinrect(masterimage.cgimage, temprect);          auiimage = [uiimage imagewithcgimage: tempsubimage];          imgview = [[uiimageview alloc] initwithimage:auiimage];          imgview.tag =i;          i++;          nslog(@"original tags = %d",label.tag);          [cellarray addobject: auiimage];                  auiimage = nil;         cgimagerelease(tempsubimage);      } } } 

now know can determine imageview has been touched of tag of imageview dont know how check tags in touchesbegan method.. can possibly differentiate uiimageview on basis of touch??

- (void)touchesbegan:(nsset *)touches withevent:(uievent *)event {   uitouch *mytouch = [touches anyobject]; cgpoint location = [mytouch locationinview:imgview];      nslog(@"touch  %@",imgview.tag);  } 

new code:

- (void) setupcellsusingimage: (uiimage *) masterimage {    rows = 4;  cols = 4;  containercellheight=hight/4; containercellwidth=width/4;   nsinteger row, col; cgimageref tempsubimage; cgrect temprect; cgfloat ypos, xpos;   uiimage * auiimage; uiimageview *label;  cellarray = [[nsmutablearray new] autorelease]; int =0;  (row=0; row < rows; row++) {     ypos = row * containercellheight;     (col=0; col < cols; col++) {         xpos = col * containercellwidth;         label = [[uiimageview alloc]init];         temprect = cgrectmake(xpos, ypos, containercellwidth, containercellheight);               tempsubimage = cgimagecreatewithimageinrect(masterimage.cgimage, temprect);          auiimage = [uiimage imagewithcgimage: tempsubimage];          imgview = [[uiimageview alloc] initwithimage:auiimage];          [self.view addsubview:imgview]; // add uiimageview here          imgview =cgrectmake(xpos, ypos, containercellwidth-1, containercellheight-1);          imgview.tag =i;          i++;          nslog(@"original tags = %d",label.tag);          [cellarray addobject: auiimage];                  auiimage = nil;         cgimagerelease(tempsubimage);      } } }    - (void)viewdidload {      uiimage *mimage = [uiimage imagenamed:@"menu.png"];      hight = mimage.size.height;      width = mimage.size.width;      [self setupcellsusingimage:mimage];  [`super viewdidload];`  } 

please try this:

- (void)touchesbegan:(nsset *)touches withevent:(uievent *)event  {     uitouch *mytouch = [touches anyobject];     cgpoint location = [mytouch locationinview:imgview];          uiview *hitview = [self.view hittest:location withevent:event];     nslog(@"hitview %@",hitview);      uiimageview *hitimageview = nil;      if([hitview iskindofclass:[uiimageview class]]) {         hitimageview = (uiimageview *)hitimageview;     }       nslog(@"touched %@", hitimageview); } 

Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -