How do you detect touches in specific UIView when sliding finger across mutiple UIViews

六月ゝ 毕业季﹏ 提交于 2019-12-24 15:26:36

问题


The scenario I am trying to solve is I have several UIViews as subviews of a master UIView. What I want to be able to do is highlight a views rect by lets say changing its border as a finger slides across the view..similar to what happens when you move/drag your mouse cursor over a hypertext link.


回答1:


You can get the location of the touch inside your touchesMoved: method, then ask the master UIView which view was touched:

- (void)touchesMoved: (NSSet *)touches withEvent:(UIEvent *)event {
    UIView *subview = [masterView hitTest:[[touches anyObject] locationInView:masterView] withEvent:nil];
...
}


来源:https://stackoverflow.com/questions/6078001/how-do-you-detect-touches-in-specific-uiview-when-sliding-finger-across-mutiple

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!