我有一个名为 Card 的 UIView 子类,我在板上移动并放置在称为插槽的热点上。当我放下卡片时,我使用 hitTest 来确定我是否将卡片放在我的一个热点上。我想获得那个热点的属性,但我无法让它正常工作。我唯一的猜测是 hitTest 返回一个 UIView 而我的热点是一个 UIView 子类。我得到的错误是“在不是结构或联合的东西中请求成员'slotIndex'”
这是我在 Card 类中使用的 TouchesEnded 方法
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent*)event {
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInView:self.superview];
[self setUserInteractionEnabled:NO];
UIView *backView = [self.superview hitTest:location withEvent:nil];
if ([backView isKindOfClass:[CardSlot class]]) {
self.center = backView.center;
NSLog(@"Slot Number: %@", backView.slotIndex);
} else {
//Move it back to the top corner
self.center = CGPointMake(50,50);
}
[self setUserInteractionEnabled:YES];
}
我的问题是如何测试我是否在插槽热点中,然后获取该插槽的属性(UIView 子类)?