IPhone开发文档经典语句
1:Whena touch occurs inside a specific view, the system sends an event object with the touch information directly tothat view for handling. However, if the view does not handle a particular touch event, it can pass the eventobject along to its superview. If the superview does not handle the event, it passes the event object to itssuperview, and so on up the responder chain
测试:
-(void)viewDidLoad{[superviewDidLoad];UIView*view=[[UIViewalloc]initWithFrame:CGRectMake(0,0,320,480)];view.backgroundColor=[UIColorblueColor];UITapGestureRecognizer*tapGesture=[[UITapGestureRecognizeralloc]initWithTarget:selfaction:@selector(viewClick:)];[viewaddGestureRecognizer:tapGesture];UIView*view2=[[UIViewalloc]initWithFrame:CGRectMake(0,0,100,100)];view2.center=CGPointMake(self.view.frame.size.width/2.0,self.view.frame.size.height/2.0);view2.backgroundColor=[UIColorblackColor];[self.viewaddSubview:view];UIButton*button=[[UIButtonalloc]initWithFrame:CGRectMake(0,0,60,50)];button.backgroundColor=[UIColorredColor];[buttonaddTarget:selfaction:@selector(buttonClick)forControlEvents:UIControlEventTouchUpInside];button.center=CGPointMake(self.view.frame.size.width/2.0,self.view.frame.size.height/2.0);[viewaddSubview:button];[viewaddSubview:view2];}-(void)buttonClick{NSLog(@"buttonClick");}-(void)viewClick:(UITapGestureRecognizer*)tap{intred=arc4random()%255;intgreen=arc4random()%255;intblue=arc4random()%255;NSLog(@"%d%d%d",red,green,blue);tap.view.backgroundColor=[UIColorcolorWithRed:red/255.0green:green/255.0blue:blue/255.0alpha:1];}测试发现在view2上发生点击事件,由于view2并不响应该事件,于是将事件传递给它的父视图,颜色发生改变,但是该点击事件并不会通过view2传递给button,所以事件传递,仅传递给它的父视图,也就是[superviewaddsubview:subview]中得superview
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。