zoukankan      html  css  js  c++  java
  • 响应者链条

    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

    结果:

  • 相关阅读:
    R语言学习笔记:向量化
    R语言笔记:快速入门
    再分析 返回值加引用&,const
    matlab 怎么保存plot的图 到指定文件夹
    不要在头文件中使用 using namespace std;
    散列表 (Hash table,也叫哈希表)
    重载操作符 operator overloading 学习笔记
    转 XMLHttpRequest().readyState的五种状态详解
    值得回味的基础知识理解加深
    完美解决fixed 水平居中问题
  • 原文地址:https://www.cnblogs.com/Lu2015-10-03/p/5179491.html
Copyright © 2011-2022 走看看