I have One UIView
and one Draggable UIImageView
.
Background color of UIView
is green.
When I will drag the image, UIImageView
will touch UIView
.
When I drag the image over UIView
the colour of UIView
should become red.
How to check that UIImageView
reached over UIView
?
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
if (CGRectIntersectsRect(imageview.frame, view.frame)) {
view.backgroundColor=[UIColor redcolor];
}
}
you can check that with touchesBegan
method like bellow...
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
[touch locationInView:self.view];
if([touch.view isKindOfClass:[UIImageView class]])
{
///This is UIImageView
}
else if([touch.view isKindOfClass:[UIView class]])
{
///This is UIView
}
}
and when you move the UIImageView
at that time its change the backGroundColor of UIView
with bellow code...
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *tap = [touches anyObject];
CGPoint pointToMove = [tap locationInView:self.view];
if([tap.view isKindOfClass:[UIImageView class]])
{
UIImageView *tempImage=(UIImageView *) tap.view;
if ([yourView pointInside:pointToMove withEvent:event])
{
[yourView setBackgroundColor:[UIColor redColor]];
}
else{
[yourView setBackgroundColor:[UIColor clearColor]];//set backcolor which you want when `UIImageView` move outside of yourView
}
}
}
Also For Moving see the answer from this link Move UIImage only inside of another UIImage
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With