/ / Como chamar TouchesMoved para 2 UIImageView diferentes - ios, uitouch

Como chamar TouchesMoved para 2 diferentes UIImageView - ios, uitouch

Olá eu tenho 2 UIImageViews dentro UIView.

Depois de tocar UIImageView touchesBegan O método é chamado. Mas uma vez que eu arrasto UIImageView então touchesMoved é chamado. mas ao mesmo tempo touchesMoved para o segundo UIImageView também é chamado.

Você pode me ajudar como posso obter touchesMoved evento para ambos UIImageViews?

Este é o meu código

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint currentPoint = [touch locationInView:self.view];

if (CGRectContainsPoint(iv1.frame,currentPoint)==YES)
NSLog(@"iv1 Begin");
if (CGRectContainsPoint(iv2.frame,currentPoint)==YES)
NSLog(@"iv2 Begin");
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint currentPoint = [touch locationInView:self.view];
if(CGRectContainsPoint(iv1.frame,currentPoint)==YES)
NSLog(@"iv1 Moved NO");
if(CGRectContainsPoint(iv2.frame,currentPoint)==NO)
NSLog(@"iv1 Moved YES");
if(CGRectContainsPoint(iv2.frame,currentPoint)==YES)
NSLog(@"iv2 Moved NO");
if(CGRectContainsPoint(iv2.frame,currentPoint)==NO)
NSLog(@"iv2 Moved NO");
}

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint currentPoint = [touch locationInView:self.view];

if (CGRectContainsPoint(iv1.frame,currentPoint)==YES)
NSLog(@"iv1 End");
if (CGRectContainsPoint(iv1.frame,currentPoint)==YES)
NSLog(@"iv2 End");
}

Respostas:

1 para resposta № 1

Você pode usar duas saídas vinculadas a duas visualizações e este é o código para reconhecer novamente as duas visualizações dentro dos métodos de toque:

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *t = [touches anyObject];
touchedView = t.view;
if (t.view == view1) {

//todo something with view1;

} else if (t.view == view2) {

//todo something with view2

}
}