您好,登錄后才能下訂單哦!
1:When
a touch occurs inside a specific view, the system sends an event object with the touch information directly to
that view for handling. However, if the view does not handle a particular touch event, it can pass the event
object along to its superview. If the superview does not handle the event, it passes the event object to its
superview, and so on up the responder chain
測試:
- (void)viewDidLoad { [super viewDidLoad]; UIView * view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)]; view.backgroundColor = [UIColor blueColor]; UITapGestureRecognizer * tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(viewClick:)]; [view addGestureRecognizer:tapGesture]; UIView * view2 = [[UIView alloc]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 = [UIColor blackColor]; [self.view addSubview:view]; UIButton * button = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 60, 50)]; button.backgroundColor = [UIColor redColor]; [button addTarget:self action:@selector(buttonClick) forControlEvents:UIControlEventTouchUpInside]; button.center = CGPointMake(self.view.frame.size.width/2.0, self.view.frame.size.height/2.0); [view addSubview:button]; [view addSubview:view2]; } - (void)buttonClick { NSLog(@"buttonClick"); } - (void)viewClick:(UITapGestureRecognizer *)tap { int red =arc4random()%255; int green = arc4random()%255; int blue = arc4random()%255; NSLog(@"%d %d %d",red,green,blue); tap.view.backgroundColor = [UIColor colorWithRed:red/255.0 green:green/255.0 blue:blue/255.0 alpha:1]; } 測試發現在view2上發生點擊事件,由于view2并不響應該事件,于是將事件傳遞給它的父視圖,顏色發生改變,但是該點擊事件并不會通過view2傳遞給button,所以事件傳遞,僅傳遞給它的父視圖,也就是[superview addsubview:subview]中得superview
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。