San007
San007

Reputation: 762

Identify the touch moved direction

I am doing the View resize,move and rotate on single touch.

I am trying to find the touch moved direction like,

IF touch moved direction is Horizontal or Vertical then MOve the view. If touch moved direction is diagonal then resize. And if touch moved like rotate gesture then rotate the View.

I am able to identify the Horizontal or Vertical direction.

Please suggest me how i can identify the diagonal and rotation.

Upvotes: 1

Views: 1314

Answers (3)

issam
issam

Reputation: 697

in touch move function, you can identify the direction of move finger like this.

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
  [super touchesMoved:touches withEvent:event]; 
   UITouch *touch = [touches anyObject];
   CGPoint current=[touch locationInView:self];
   CGPoint last=[touch previousLocationInView:self];

   if(current.x>last.x){
      NSLog(@">>>>rigth");
   }else{
     NSLog(@">>>>left");
   }

   if(current.y>last.y){
    NSLog(@">>>>up");
   }else{
    NSLog(@">>>>down");
   }   
}

Upvotes: 1

DharaParekh
DharaParekh

Reputation: 1730

Try This:

TDResizerView

both view rotation and move is available in this

Upvotes: 1

Baby Groot
Baby Groot

Reputation: 4279

I guess for rotation, you can simply use this mehod -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event.

And for diagonal, you can compare coordinates of both the points. For diagonal, you can take help from this post also.

Upvotes: 1

Related Questions