The responder chain in iOS

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.