zoukankan      html  css  js  c++  java
  • 源码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
  • 相关阅读:
    免费申请域名
    分享学习linux网站
    二分法
    node 解决存储xss风险报告
    cf987f AND Graph
    loj2587 「APIO2018」铁人两项
    luogu3830 [SHOI2012]随机树
    luogu3343 [ZJOI2015]地震后的幻想乡
    bzoj2560 串珠子
    luogu3317 [SDOI2014]重建
  • 原文地址:https://www.cnblogs.com/laugh/p/6668814.html
Copyright © 2011-2022 走看看