响应者链条

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

结果:

转载于:https://www.cnblogs.com/Lu2015-10-03/p/5179491.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值