简体   繁体   English

当手指滑过多个UIViews时,如何检测特定UIView中的触摸

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

The scenario I am trying to solve is I have several UIViews as subviews of a master UIView. 我试图解决的场景是我有几个UIViews作为主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. 我想要做的是突出显示视图rect,让我们说当手指在视图上滑动时更改其边框...类似于在超文本链接上移动/拖动鼠标光标时发生的情况。

You can get the location of the touch inside your touchesMoved: method, then ask the master UIView which view was touched: 您可以在touchesMoved:方法中获取触摸的位置,然后向主UIView询问触摸了哪个视图:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM