1.什么是响应者
继承了UIResponder的对象就是响应者
面试题
响应者的链条是什么?
1.它是一种事件处理机制,由多个响应者对象连接起来的链条,使得事件可以沿着这些对象进行传递。
2.如果一个响应者对象不能处理某个事件或动作消息,则将该事件消息重新发给链中的上一个响应者。
3.消息沿着响应者链向上、向更高级别的对象传递,直到最终被处理。
ViewController.m
//
// ViewController.m
// 7A03.响应者链条
//
// Created by huan on 16/2/3.
// Copyright © 2016年 huanxi. All rights reserved.
//
#import "ViewController.h"
#import "CZRedViewController.h"
@interface ViewController ()
@property (nonatomic, strong) CZRedViewController *redVc;//强引用,防止控制器被销毁
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
CZRedViewController *redVc = [[CZRedViewController alloc] init];
redVc.view.frame = CGRectMake(0, 30, 300, 300);
[self.view addSubview:redVc.view];
self.redVc = redVc;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
NSLog(@"%s", __func__);
}
@end
CZRedViewController.h
#import <UIKit/UIKit.h>
@interface CZRedViewController : UIViewController
@end
CZRedViewController.m
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
NSLog(@"%s", __func__);
}
CZRedViewController.xib
CZRedView.m
#import "CZRedView.h"
@implementation CZRedView
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
NSLog(@"%s", __func__);
}
@end
结果: