如何知道用户在屏幕上触摸的视图

pra*_*eep 0 touch uiscrollview ios

如果在uiscrollview上有uiscrollview和多个子视图.如何知道用户触摸的位置,即特定视图或滚动视图(空白区域)

Ant*_* MG 5

使用这种方法:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
        UITouch *touch = [touches anyObject];
        NSLog(@"View touched: %@", touch.view);
}
Run Code Online (Sandbox Code Playgroud)

每次手指触摸屏幕时都会调用此方法,触摸会知道它触摸的是哪个视图.

编辑:它不能在UIScrollView上工作,因为滚动视图会自动触摸,请检查:

在UIScrollView中滚动时未调用touchesBegan方法

如何在UIScrollView中启用触摸?