本文主要是介绍9.2 响应者链,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
MyView.h
<UIKit/UIKit.h>
@interface MyView : UIView
@property(strong,nonatomic)NSString*name;
@end
#import "MyView.h"@implementation MyView
#pragma mark 让响应者链往下传递
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{NSLog(@"i am %@",self.name);[self.nextResponder touchesBegan:touches withEvent:event];
}
@end
#import "ViewController.h"
#import "MyView.h"
@interface ViewController ()@end@implementation ViewController- (void)viewDidLoad {[super viewDidLoad];MyView *blueView=[[MyView alloc]initWithFrame:CGRectMake(10, 10, 200, 200)];blueView.backgroundColor=[UIColor blueColor];blueView.name=@"blue";[self.view addSubview:blueView];MyView *yellowView=[[MyView alloc]initWithFrame:CGRectMake(40, 40, 140, 140)];yellowView.backgroundColor=[UIColor yellowColor];yellowView.name=@"yellow";[blueView addSubview:yellowView];MyView *redView=[[MyView alloc]initWithFrame:CGRectMake(40, 40, 100, 100)];redView.backgroundColor=[UIColor redColor];redView.name=@"red";[yellowView addSubview:redView];redView.userInteractionEnabled=NO;// Do any additional setup after loading the view, typically from a nib.
}@end
这篇关于9.2 响应者链的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!