0
我有子视图的视图,这些子视图的UIView的子类,在本例中的子类被称为ESDcelda可可触摸则hitTest withEvent可以识别UIView子类
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
UIImage *img = [UIImage imageNamed:@"lgrey091.gif"];
[self setBackgroundColor:[UIColor colorWithPatternImage:img]];
ESDcelda *cel1 = [[ESDcelda alloc] initWithTipo:1];
[cel1 setFrame:CGRectMake(100, 100, cel1.frame.size.width, cel1.frame.size.height)];
[self addSubview:cel1];
cel1 = [[ESDcelda alloc] initWithTipo:2];
[cel1 setFrame:CGRectMake(300, 100, cel1.frame.size.width, cel1.frame.size.height)];
[self addSubview:cel1];
}
return self;
}
现在我triyng知道什么样的UIView我指向与以下方法的touchEvents,但在日志指针“Vista”只识别自我类或UIView类,有任何方法来识别子类“celdaSel”?
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [[touches allObjects] objectAtIndex:0];
[self perfTouch:touch];
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [[touches allObjects] objectAtIndex:0];
[self perfTouch:touch];
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [[touches allObjects] objectAtIndex:0];
[self perfTouch:touch];
}
-(void)perfTouch:(UITouch *)touch
{
CGPoint punto = [touch locationInView:self];
UIView *vista = (ESDcelda *)[self hitTest:punto withEvent:nil];
if (![vista isKindOfClass:[self class]])
{
celdaSel = (ESDcelda *)vista;
[celdaSel seleccion:YES];
}
else
{
if (celdaSel != nil)
{
[celdaSel seleccion:NO];
}
}
}
高兴你理解了它。不要把“解决”放在标题中 - 点击答案旁边的复选标记,让别人知道它已经解决。 –
在标题中解决这个词是通过页面22小时让我检查我自己的答案作为正确的答案,现在有更好的方法来做到这一点? –
对不起,我的意思是一旦你能够接受,就做到这一点。最近太被剥夺了睡眠:) –