(1)設置根視圖控制器
(2)RootViewController.m
- (void)viewDidLoad { [super viewDidLoad]; MyView *view = [[MyView alloc] initWithFrame:CGRectMake(0, 20, 320, 300)]; view.backgroundColor = [UIColor grayColor]; [self.view addSubview:view]; } - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { NSLog(@"viewCtrl touchesBegan"); [self.nextResponder touchesBegan:touches withEvent:event]; }
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { NSLog(@"myView touchesBegan"); //將事件傳遞給下一個響應者 /* nextResponder可以取得下一個響應者 */ [self.nextResponder touchesBegan:touches withEvent:event]; }
//window分發事件的方法 - (void)sendEvent:(UIEvent *)event { NSLog(@"window sendEvent"); [super sendEvent:event]; } - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { NSLog(@"window touchesBegan"); }