源码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

 

posted @ 2017-04-05 15:07  laugh  阅读(182)  评论(0编辑  收藏  举报