hi have 5 imageviews, off them subviews in navigation bar. want tapcounts each imageview, think have use touchesbegan method. actually, there's no touch event detected in every imageview. precisely, touchesbegan detected in toolbar. hierarchy :
uiviewcontroller -> uitoolbar
-> uinavigationbar -> uiimageview
this code :
-(void)touchesbegan:(nsset *)touches withevent:(uievent *)event{ int indexsegment = _docsegmentedcontrol.selectedsegmentindex; cgrect frametouch; if (indexsegment == 0) { frametouch = frame; }else if (indexsegment == 1) { frametouch = frame1; }else if (indexsegment == 2) { frametouch = frame2; }else if (indexsegment == 3) { frametouch = frame3; }else if (indexsegment == 4) { frametouch = frame4; } uitouch *touch = [touches anyobject]; //--image 0-- cgpoint gesturestartpoint0 = [touch locationinview:imageview]; if (cgrectcontainspoint(frame, gesturestartpoint0)) { [nsobject cancelpreviousperformrequestswithtarget:imageview selector:@selector(segmentitemtapped:) object:nil]; }else { [nsobject cancelpreviousperformrequestswithtarget:imageview selector:@selector(segmentitemtapped:) object:nil]; } //--image 1-- cgpoint gesturestartpoint1 = [touch locationinview:imageview1]; if (cgrectcontainspoint(frame1, gesturestartpoint1)) { [nsobject cancelpreviousperformrequestswithtarget:imageview1 selector:@selector(segmentitemtapped:) object:nil]; }else { nslog(@"false "); } //--image 2-- cgpoint gesturestartpoint2 = [touch locationinview:imageview2]; if (cgrectcontainspoint(frame2, gesturestartpoint2)) { [nsobject cancelpreviousperformrequestswithtarget:imageview2 selector:@selector(segmentitemtapped:) object:nil]; }else { nslog(@"false "); } //--image 3-- cgpoint gesturestartpoint3 = [touch locationinview:imageview3]; if (cgrectcontainspoint(frame3, gesturestartpoint3)) { [nsobject cancelpreviousperformrequestswithtarget:imageview3 selector:@selector(segmentitemtapped:) object:nil]; }else { nslog(@"false "); } //--image 4-- cgpoint gesturestartpoint4 = [touch locationinview:imageview4]; if (cgrectcontainspoint(frame4, gesturestartpoint4)) { [nsobject cancelpreviousperformrequestswithtarget:imageview4 selector:@selector(segmentitemtapped:) object:nil]; }else { nslog(@"false "); }
}
-(void)touchesended:(nsset *)touches withevent:(uievent *)event{ int indexsegment = _docsegmentedcontrol.selectedsegmentindex; int counter = [_docsegmentmodels count]; nslog(@"index di touches ended : %d", indexsegment); cgrect frametouch; if (indexsegment == 0) { frametouch = frame; }else if (indexsegment == 1) { frametouch = frame1; }else if (indexsegment == 2) { frametouch = frame2; }else if (indexsegment == 3) { frametouch = frame3; }else if (indexsegment == 4) { frametouch = frame4; } uitouch *touch = [touches anyobject]; //--image 0-- cgpoint gestureendpoint0 = [touch locationinview:imageview]; if (cgrectcontainspoint(frame, gestureendpoint0)) { //mencari bagian yg berimpitan dari posisi tap dengan frame segmen if (counter>0){ if (touch.tapcount <= 2) { [self performselector:@selector(segmentitemtapped:) withobject:nil]; } }else { [nsobject cancelpreviousperformrequestswithtarget:navbar selector:@selector(segmentitemtapped:) object:nil]; } }else { nslog(@"cgrectcontaintspoint0 : %d", cgrectcontainspoint(frame, gestureendpoint0)); } //--image 1-- cgpoint gestureendpoint1 = [touch locationinview:imageview1]; if (cgrectcontainspoint(frame1, gestureendpoint1)) { //mencari bagian yg berimpitan dari posisi tap dengan frame segmen if (counter>0){ if (touch.tapcount <= 2) { [self performselector:@selector(segmentitemtapped:) withobject:nil]; } }else { [nsobject cancelpreviousperformrequestswithtarget:navbar selector:@selector(segmentitemtapped:) object:nil]; } }else { nslog(@"cgrectcontaintspoint1 : %d", cgrectcontainspoint(frame1, gestureendpoint1)); } //--image 2-- cgpoint gestureendpoint2 = [touch locationinview:imageview2]; if (cgrectcontainspoint(frame2, gestureendpoint2)) { //mencari bagian yg berimpitan dari posisi tap dengan frame segmen if (counter>0){ if (touch.tapcount <= 2) { [self performselector:@selector(segmentitemtapped:) withobject:nil]; } }else { [nsobject cancelpreviousperformrequestswithtarget:navbar selector:@selector(segmentitemtapped:) object:nil]; } }else { nslog(@"cgrectcontaintspoint2 : %d", cgrectcontainspoint(frame2, gestureendpoint2)); } //--image 3-- cgpoint gestureendpoint3 = [touch locationinview:imageview3]; if (cgrectcontainspoint(frame3, gestureendpoint3)) { //mencari bagian yg berimpitan dari posisi tap dengan frame segmen if (counter>0){ if (touch.tapcount <= 2) { [self performselector:@selector(segmentitemtapped:) withobject:nil]; } }else { [nsobject cancelpreviousperformrequestswithtarget:navbar selector:@selector(segmentitemtapped:) object:nil]; } }else { nslog(@"cgrectcontaintspoint3 : %d", cgrectcontainspoint(frame3, gestureendpoint3)); } //--image 4-- cgpoint gestureendpoint4 = [touch locationinview:imageview4]; if (cgrectcontainspoint(frame4, gestureendpoint4)) { //mencari bagian yg berimpitan dari posisi tap dengan frame segmen if (counter>0){ if (touch.tapcount <= 2) { [self performselector:@selector(segmentitemtapped:) withobject:nil]; } }else { [nsobject cancelpreviousperformrequestswithtarget:navbar selector:@selector(segmentitemtapped:) object:nil]; } }else { nslog(@"cgrectcontaintspoint4 : %d", cgrectcontainspoint(frame4, gestureendpoint4)); }
}
is there have define connect touchesbegan imageviews?? me please regards -risma-
oh, man. you're write lot of duplicated code. scary moment when need change something.
touch in imageview detected if userinteractionenabled == yes; , can use own class (child of uiimageview) handle , work touches.
Comments
Post a Comment