Ios 使用hitTest:withEvent:返回自定义对象

Ios 使用hitTest:withEvent:返回自定义对象,ios,objective-c,cocoa-touch,Ios,Objective C,Cocoa Touch,我想使用-(UIView*)hitTest:(CGPoint)pointwithevent:(UIEvent*)event在屏幕上返回一个变量完整的自定义对象 我试过: - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; CGPoint location = [touch locationInView:self.view];

我想使用
-(UIView*)hitTest:(CGPoint)pointwithevent:(UIEvent*)event
在屏幕上返回一个变量完整的自定义对象

我试过:

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [touches anyObject];
    CGPoint location = [touch locationInView:self.view];
    SLDSlide *selected = (SLDSlide *)[self hitTest:location withEvent:event];
}


但是它告诉我这些方法没有
@接口
,我也不知道如何自己编写一个接口来返回我想要的对象(
SLDSlide
,它是
UIImageView
的子类)

SLDSlide *selected = nil;

for ( UIView *view in self.view.subviews )
{
    if ( [view isKindOfClass:[SLDSlide class]] )
        if ( CGRectContainsPoint( view.frame, location ) )
            selected = (SLDSlide *)view;
}

if ( selected )
    NSLog( @"found one: %@", selected );

请注意,如果视图层次结构有多个级别,则代码需要在层次结构中递归搜索,因此,这仅适用于所有
SLDSlide
对象都是视图控制器的
self.view

的子视图的情况,它获取对象,但不保留对象的任何自定义变量。你知道怎么做吗?
SLDSlide *selected = nil;

for ( UIView *view in self.view.subviews )
{
    if ( [view isKindOfClass:[SLDSlide class]] )
        if ( CGRectContainsPoint( view.frame, location ) )
            selected = (SLDSlide *)view;
}

if ( selected )
    NSLog( @"found one: %@", selected );