Cocoa Touch HitTest UViewサブクラスを認識できます
-
11-12-2019 - |
質問
サブビューでビューを持っている、これらのサブビューはUIViewのサブクラスです。サブクラスはESDCELDA と呼ばれます。
- (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;
}
.
今すぐ私はTryyng私は以下の方法で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];
}
}
}
. 解決
解決策、ステップがあります
- メインビューのタッチを扱うコードを残し、どこにあるのか。
v
.-(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]; if (self.celdaSel != nil) { NSLog(@"%d",self.celdaSel.elemento); } } -(void)perfTouch:(UITouch *)touch { CGPoint punto = [touch locationInView:self]; [self hitTest:punto withEvent:nil]; }
- ESDCELDAと呼ばれるPointSindideをオーバーライドする:現在のシングルタッチがビュー上にあるかどうかを知るために、「Inter」は、タッチが表示されているかどうか「SELECCIONADA」を知らせる変数です。ビューが強調表示されている、 "conten"はsuperviewへのポインタで、 "seleccion:"はそれが自己の表示を強調表示する方法です。
v
.-(BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event { BOOL inter = [super pointInside:point withEvent:event]; if (inter) { //NSLog(@"%i, %@", inter, self); if (!self.selecionada) { [self seleccion:YES]; if (self.conten.celdaSel != nil) [self.conten.celdaSel seleccion:NO]; [self.conten setCeldaSel:self]; } } else { if (self.selecionada) { [self seleccion:NO]; [self.conten setCeldaSel:nil]; } } return inter; }
- ESDCELDAと呼ばれるPointSindideをオーバーライドする:現在のシングルタッチがビュー上にあるかどうかを知るために、「Inter」は、タッチが表示されているかどうか「SELECCIONADA」を知らせる変数です。ビューが強調表示されている、 "conten"はsuperviewへのポインタで、 "seleccion:"はそれが自己の表示を強調表示する方法です。
所属していません StackOverflow