Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何支持触摸在各种对象之间移动?_Ios_Touchesmoved - Fatal编程技术网

Ios 如何支持触摸在各种对象之间移动?

Ios 如何支持触摸在各种对象之间移动?,ios,touchesmoved,Ios,Touchesmoved,我的应用程序中有一些标签如下 我需要做的是,当点击标签时,我只在屏幕底部显示标签名称。当分别单击每个单元格时,它工作正常。但是我想显示这些变化,即使用户点击一个特定的标签并将手指移动到另一个标签上。也就是说,一旦他按下屏幕上的按钮,他的手指就会移动,我想追踪这些地方并显示变化。我该怎么做?请简要解释一下 提前感谢默认情况下,触摸事件仅发送到它们开始所在的视图。因此,最简单的方法是将所有标签放在拦截触摸事件的容器视图中,并让容器视图决定如何处理事件 首先为容器创建UIView子类,并通过覆盖hi

我的应用程序中有一些标签如下

我需要做的是,当点击标签时,我只在屏幕底部显示标签名称。当分别单击每个单元格时,它工作正常。但是我想显示这些变化,即使用户点击一个特定的标签并将手指移动到另一个标签上。也就是说,一旦他按下屏幕上的按钮,他的手指就会移动,我想追踪这些地方并显示变化。我该怎么做?请简要解释一下


提前感谢

默认情况下,触摸事件仅发送到它们开始所在的视图。因此,最简单的方法是将所有标签放在拦截触摸事件的容器视图中,并让容器视图决定如何处理事件

首先为容器创建UIView子类,并通过覆盖
hitTest:withEvent:

-(UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
    // intercept touches
    if ([self pointInside:point withEvent:event]) {
        return self;        
    }
    return nil;
}
将该自定义类设置为容器视图的类。然后,在容器视图上实现各种
touch*:withEvent:
方法。在您的情况下,类似这样的方法应该会起作用:

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    // determine which view is under the touch
    UIView* view = [super hitTest:[[touches anyObject] locationInView:self] withEvent:nil];

    // get that label's text and set it on the indicator label
    if (view != nil && view != self) {
        if ([view respondsToSelector:@selector(text)]) {
            // update the text of the indicator label
            [[self indicatorLabel] setText:[view text]];
        }
    }
}
你不能在superview上使用吗?或者用