1

How can I move CGRect with uitouches? If anyone has idea please explain.

if(areaSelected)
        return;
    UITouch *mytouch=[[touches allObjects] objectAtIndex:0];
    [myPath addLineToPoint:[mytouch locationInView:self]];

[self setNeedsDisplay];
alicjasalamon
  • 4,171
  • 15
  • 41
  • 65
Shehbaz Khan
  • 1,892
  • 3
  • 24
  • 31
  • Didnt understand ur question ... what do you want to achieve ? – IronManGill Aug 28 '12 at 06:52
  • @Shehbaz do want to draw line? – Arun Aug 28 '12 at 06:53
  • i want to move my a rectangle and this is myrect code CGRect cropRect= [myPath bounds]; // Retina cropRect= CGRectMake(cropRect.origin.x-10, cropRect.origin.y, cropRect.size.width*1.5, cropRect.size.height*1.5); – Shehbaz Khan Aug 28 '12 at 07:03
  • 1
    so u want to move your cropped image from x to y .. – Arun Aug 28 '12 at 07:08
  • yes,please help,and want to move image everywhere – Shehbaz Khan Aug 28 '12 at 07:13
  • 1
    try this.... -(void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event { UITouch *touch = [[event allTouches] anyObject]; // Get Touch location CGPoint touchLocation = [touch locationInView:touch.view]; // Set touch location's center to ImageView imageView.center = touchLocation; } if you found solution just intimate me... – Arun Aug 28 '12 at 11:06

2 Answers2

1

Hi as per my understanding you need to move the cropped image to one place to other place so you need to code it in the touches stuff...

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [[event allTouches] anyObject];
    CGPoint location = [touch locationInView:touch.view];
    cloud.center = location;
}

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    [self touchesBegan:touches withEvent:event];
}

Here cloud is the UIImageView you can make it as cropped image ....

 cloud.image=croppedImage;   //[you must assign this first...]

i hope it helps you...

Arun
  • 3,406
  • 4
  • 30
  • 55
0

You need to reset the frame of the rectangle:

[cropRect setFrame:CGRectMake(<new x coordinate>, <new y coordinate>, width, height)]
Bijoy Thangaraj
  • 5,434
  • 4
  • 43
  • 70