Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

[IOS SDK]- touchesBegan with specific object?

When I touch anywhere on screen touchesBegan event triggered. but I couldn't manage how if I touch specific object as like UIImageView?

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

 UITouch *touch = [[event allTouches] anyObject];

 CGPoint location = [touch locationInView: touch.view];

 imageView.center = location;

}

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {

 [self touchesBegan:touches withEvent:event];

}
like image 631
modus Avatar asked Nov 25 '25 07:11

modus


1 Answers

Ok, found the solution, here is the code:

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {

    UITouch *touch = [[event allTouches] anyObject];

    if ([touch view] == imageView) {

        CGPoint location = [touch locationInView: self.view];

        imageView.center = location;

    }

}
like image 83
modus Avatar answered Nov 27 '25 23:11

modus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!