• 源码03-事件的响应(处理)


    //  HMViewController.m
    //  02-事件传递(掌握)
    #import "HMViewController.h"
    
    @interface HMViewController ()
    @end
    @implementation HMViewController
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        // Do any additional setup after loading the view, typically from a nib.
    }
    
    - (void)didReceiveMemoryWarning
    {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    
    
    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
    {
        NSLog(@"%s",__func__);
    }
    @end
    //  HMBaseView.h
    //  02-事件传递(掌握)
    #import <UIKit/UIKit.h>
    
    @interface HMBaseView : UIView
    
    @end
    //  HMBaseView.m
    //  02-事件传递(掌握)
    #import "HMBaseView.h"
    @implementation HMBaseView
    
    //- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
    //{
    //    NSLog(@"%@----touchesBegan",[self class]);
    //}
    
    @end
    //  HMWhite.h
    //  02-事件传递(掌握)
    #import "HMBaseView.h"
    
    @interface HMWhite : HMBaseView
    
    @end
    //  HMWhite.m
    //  02-事件传递(掌握)
    #import "HMWhite.h"
    
    @implementation HMWhite
    
    //- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
    //{
    //    NSLog(@"%s",__func__);
    //    
    //    [super touchesBegan:touches withEvent:event];
    //    
    //}
    
    
    @end
    //  HMGreenView.h
    //  02-事件传递(掌握)
    #import "HMBaseView.h"
    
    @interface HMGreenView : HMBaseView
    
    @end
    //  HMGreenView.m
    //  02-事件传递(掌握)
    #import "HMGreenView.h"
    
    @implementation HMGreenView
    
    - (id)initWithFrame:(CGRect)frame
    {
        self = [super initWithFrame:frame];
        if (self) {
            // Initialization code
        }
        return self;
    }
    
    /*
    // Only override drawRect: if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    - (void)drawRect:(CGRect)rect
    {
        // Drawing code
    }
    */
    
    @end
    //
    //  HMOrange.h
    //  02-事件传递(掌握)
    #import "HMBaseView.h"
    
    @interface HMOrange : HMBaseView
    
    @end
    //
    //  HMOrange.m
    //  02-事件传递(掌握)
    #import "HMOrange.h"
    
    @implementation HMOrange
    //- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
    //{
    //    NSLog(@"%s",__func__);
    //    [super touchesBegan:touches withEvent:event];
    //}
    - (id)initWithFrame:(CGRect)frame
    {
        self = [super initWithFrame:frame];
        if (self) {
            // Initialization code
            
            
            
        }
        return self;
    }
    
    /*
    // Only override drawRect: if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    - (void)drawRect:(CGRect)rect
    {
        // Drawing code
    }
    */
    
    @end
    //
    //  HMYellowView.h
    //  02-事件传递(掌握)
    
    #import "HMBaseView.h"
    
    @interface HMYellowView : HMBaseView
    
    @end
    //
    //  HMYellowView.m
    //  02-事件传递(掌握)
    #import "HMYellowView.h"
    
    @implementation HMYellowView
    
    - (id)initWithFrame:(CGRect)frame
    {
        self = [super initWithFrame:frame];
        if (self) {
            // Initialization code
        }
        return self;
    }
    
    // touchesBegan默认做法:把事件传递上一个响应者
    // 黄色的上一个响应者是蓝色,默认上一个响应者是父控件
    //- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
    //{
    //     NSLog(@"%s",__func__);
    //    
    //    // super -> 父类 不是父控件
    //    [super touchesBegan:touches withEvent:event];
    //}
    //
    /*
    // Only override drawRect: if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    - (void)drawRect:(CGRect)rect
    {
        // Drawing code
    }
    */
    
    @end
    //  HMRedView.m
    //  02-事件传递(掌握)
    #import "HMRedView.h"
    
    @implementation HMRedView
    
    - (id)initWithFrame:(CGRect)frame
    {
        self = [super initWithFrame:frame];
        if (self) {
            // Initialization code
        }
        return self;
    }
    
    /*
    // Only override drawRect: if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    - (void)drawRect:(CGRect)rect
    {
        // Drawing code
    }
    */
    
    @end
    本人无商业用途,仅仅是学习做个笔记,特别鸣谢小马哥,学习了IOS,另日语学习内容有需要文本和音频请关注公众号:riyuxuexishuji
  • 相关阅读:
    函数地址经典基础C++笔试题(附答案)
    类型事务修改 mysql 表类型 实际测试可执行
    ARM7,ARM9有哪些区别
    I2C,SPI,UART总线的区别详解
    I²C
    AnyWhere——面向设备的编程模式
    Linux设备驱动编程之内存与I/O操作
    http://www.ibm.com/developerworks/cn/linux/lcnspidermonkey/index.html
    PCI Express总线接口板的设计与实现
    armfans文章搜集
  • 原文地址:https://www.cnblogs.com/laugh/p/6668814.html
Copyright © 2020-2023  润新知