The responder chain is when the child view does not respond, the parent view responds to the event, and the parent view responds
#import"RootViewController.h"#import"ResponderView.h"@interface Rootviewcontroller () @end @implementation Rootviewcontroller- (void) viewdidload {[Super viewdidload]; //Do any additional setup after loading the view.Responderview *viewtop = [[Responderview alloc] Initwithframe:cgrectmake (0,0, the,284)]; Viewtop.tag= -; Viewtop.backgroundcolor=[Uicolor Redcolor]; [Self.view Addsubview:viewtop]; [Viewtop release]; Responderview*viewdow = [[Responderview alloc] Initwithframe:cgrectmake (0,284, the,284)]; Viewdow.tag=101; Viewdow.userinteractionenabled=NO; Viewdow.backgroundcolor=[Uicolor Yellowcolor]; [Self.view Addsubview:viewdow]; [Viewdow release]; Responderview*viewne1 = [[Responderview alloc] Initwithframe:cgrectmake ( +, +, -,204)]; Viewne1.tag=102; Viewne1.backgroundcolor=[Uicolor Greencolor]; [Viewdow Addsubview:viewne1]; [ViewNe1 release]; Responderview*viewne2 = [[Responderview alloc] Initwithframe:cgrectmake ( +, +, the,124)]; Viewne2.tag=103; Viewne2.backgroundcolor=[Uicolor Bluecolor]; [ViewNe1 Addsubview:viewne2]; [ViewNe2 release]; UILabel*lab = [[UILabel alloc] Initwithframe:cgrectmake ( -, -, -, -)]; Lab.backgroundcolor=[Uicolor Greencolor]; //lab.userinteractionenabled = NO;Lab.tag =104; [Viewtop Addsubview:lab]; [Lab release]; UIButton*BTN =[UIButton Buttonwithtype:uibuttontypecustom]; //Btn.backgroundcolor = [Uicolor bluecolor];Btn.frame = CGRectMake (0,0, -, -); Btn.tag= the; //btn.userinteractionenabled = NO;[BTN Settitle:@"Button"Forstate:uicontrolstatenormal]; [Lab addsubview:btn];}- (void) didreceivememorywarning {[Super didreceivememorywarning]; //Dispose of any resources the can be recreated.}- (void) Touchesbegan: (Nsset *) touches withevent: (Uievent *)Event{NSLog (@"I am the view controller I respond!");} @end
#import"ResponderView.h"@implementation Responderview- (void) Touchesbegan: (Nsset *) touches withevent: (Uievent *)Event{ Switch(Self.tag) { Case -: NSLog (@"Red View"); Break; Case 101: NSLog (@"Yellow View"); Break; Case 102: NSLog (@"Green View"); Break; Case 103: NSLog (@"Blue View"); Break; Case 104: NSLog (@"FDSF View"); Break; Case the: NSLog (@"fdsfddddd View"); Break; default: Break; }}- (void) touchesmoved: (Nsset *) touches withevent: (Uievent *)Event{ }- (void) touchescancelled: (Nsset *) touches withevent: (Uievent *)Event{ }- (void) touchesended: (Nsset *) touches withevent: (Uievent *)Event{} @end
The responder chain in iOS