如何支持跨各种对象的触摸移动?

| 我的应用程序中有一些这样的标签... 我需要做的是,单击标签时,仅在屏幕底部显示标签名称。分别单击每个单元格时,它可以正常工作。但是,即使用户单击特定标签并将手指移到另一个标签上,我也希望显示这些更改。就是说,一旦他在屏幕上按一下,无论手指移动到哪里,我都希望找到这些地方并显示变化。我怎样才能做到这一点?请简要说明。 提前致谢     
已邀请:
默认情况下,触摸事件仅发送到它们开始的视图。因此,要做的最简单的方法是将所有标签放入拦截触摸事件的容器视图中,容器视图决定如何处理事件。 首先为容器创建一个UIView子类,并通过重写ѭ0来拦截触摸事件:
-(UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
    // intercept touches
    if ([self pointInside:point withEvent:event]) {
        return self;        
    }
    return nil;
}
将该自定义类设置为容器视图的类。然后,在容器视图上实现各种
touches*: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]];
        }
    }
}
    

要回复问题请先登录注册