我有一个包含许多子视图的视图控制器。当用户点击屏幕时,我想知道触摸了哪个子视图。有没有办法确定这个?
-(void)touchesEnded: (NSSet *) touches withEvent: (UIEvent *) event {
UIView *touchedView = ...
if(touchedView == self.importantView){
//do something cool.
}
}
答案 0 :(得分:1)
试试这个:
UITouch *touch = (UITouch *)[touches anyObject];
UIView *touchView = touch.view;