2013-09-02 3 views
2

Je dois trouver le point final à partir du point de départ et du point déplacé.Comment trouver les coordonnées du point de départ à partir du point de départ et du point défilant

Je fais de l'animation et je dois déplacer View lorsque l'utilisateur fait glisser la vue, puis je dois traverser hors de l'écran et ramener au point d'origine.

En ce moment j'ai utilisé UISwipeGestureRecognizer pour détecter le balayage sur Move. Voici le code.

UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipe:)]; 
    UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipe:)]; 
    UISwipeGestureRecognizer *swipeUp = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipe:)]; 
    UISwipeGestureRecognizer *swipeDown = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipe:)]; 

    // Setting the swipe direction. 
    [swipeLeft setDirection:UISwipeGestureRecognizerDirectionLeft]; 
    [swipeRight setDirection:UISwipeGestureRecognizerDirectionRight]; 
    [swipeUp setDirection:UISwipeGestureRecognizerDirectionUp]; 
    [swipeDown setDirection:UISwipeGestureRecognizerDirectionDown]; 

    // Adding the swipe gesture on image view 
    [_view1 addGestureRecognizer:swipeLeft]; 
    [_view1 addGestureRecognizer:swipeRight]; 
    [_view1 addGestureRecognizer:swipeUp]; 
    [_view1 addGestureRecognizer:swipeDown]; 

Handling Swipe

- (void)handleSwipe:(UISwipeGestureRecognizer *)swipe { 

    CGPoint movedPoint = [swipe locationInView:swipe.view]; 

    if (swipe.direction == UISwipeGestureRecognizerDirectionLeft) { 
     NSLog(@"Left Swipe"); 

     CGPoint startPoint = _view1.frame.origin; 
     //Diffence Moved 
     float movedDiffence_X = startPoint.x - movedPoint.x; 
     float movedDiffence_Y = startPoint.y - movedPoint.y; 
     //How can I find END POINT BASED ON THIS DATA 

     [UIView animateWithDuration:1 animations:^{ 
      _view1.center = CGPointMake(movedDiffence_X *3,movedDiffence_Y *3); 
      _view1.transform = CGAffineTransformMakeRotation(-0.86); 
     } completion:^(BOOL finished) { 
      [UIView animateWithDuration:0.8 animations:^{ 
       _view1.center = CGPointMake(84, 240); 
       _view1.transform = CGAffineTransformMakeRotation(0.36); 
      } completion:^(BOOL finished) { 

      }]; 
     }]; 

    } 
    if (swipe.direction == UISwipeGestureRecognizerDirectionRight) { 
     NSLog(@"Right Swipe"); 
     CGPoint startPoint = _view1.frame.origin; 
     //Diffence Moved 
     float movedDiffence_X = startPoint.x - movedPoint.x; 
     float movedDiffence_Y = startPoint.y - movedPoint.y; 

     //How can I find 

     [UIView animateWithDuration:1 animations:^{ 
      _view1.center = CGPointMake(movedDiffence_X *3,movedDiffence_Y *3); 
      _view1.transform = CGAffineTransformMakeRotation(-0.86); 
     } completion:^(BOOL finished) { 
      [UIView animateWithDuration:0.8 animations:^{ 
       _view1.center = CGPointMake(84, 240); 
       _view1.transform = CGAffineTransformMakeRotation(0.36); 
      } completion:^(BOOL finished) { 

      }]; 
     }]; 
    } 

    if (swipe.direction == UISwipeGestureRecognizerDirectionUp) { 
     NSLog(@"Up Swipe"); 

     CGPoint startPoint = _view1.frame.origin; 
     //Diffence Moved 
     float movedDiffence_X = startPoint.x - movedPoint.x; 
     float movedDiffence_Y = startPoint.y - movedPoint.y; 

     //How can I find 

     [UIView animateWithDuration:1 animations:^{ 
      _view1.center = CGPointMake(movedDiffence_X *3,movedDiffence_Y *3); 
      _view1.transform = CGAffineTransformMakeRotation(-0.86); 
     } completion:^(BOOL finished) { 
      [UIView animateWithDuration:0.8 animations:^{ 
       _view1.center = CGPointMake(84, 240); 
       _view1.transform = CGAffineTransformMakeRotation(0.36); 
      } completion:^(BOOL finished) { 

      }]; 
     }]; 
    } 
    if (swipe.direction == UISwipeGestureRecognizerDirectionDown) { 
     NSLog(@"Down Swipe"); 

     CGPoint startPoint = _view1.frame.origin; 
     //Diffence Moved 
     float movedDiffence_X = startPoint.x - movedPoint.x; 
     float movedDiffence_Y = startPoint.y - movedPoint.y; 

     //How can I find 

     [UIView animateWithDuration:1 animations:^{ 
      _view1.center = CGPointMake(movedDiffence_X *3,movedDiffence_Y *3); 
      _view1.transform = CGAffineTransformMakeRotation(-0.86); 
     } completion:^(BOOL finished) { 
      [UIView animateWithDuration:0.8 animations:^{ 
       _view1.center = CGPointMake(84, 240); 
       _view1.transform = CGAffineTransformMakeRotation(0.36); 
      } completion:^(BOOL finished) { 

      }]; 
     }]; 
    } 

} 

enter image description here

Quand je Balayez vers la vue n ° 1 alors que je peux obtenir le point déplacé dans SwipeHadler (handleSwipe) Méthode

Je peut également détecter la direction de balayage. Mais mon problème est que je dois à travers No.1 Voir hors de l'écran. Pour cela, je dois trouver le point d'extrémité ..

Alors, comment puis-je trouver Endpoint à partir du point de départ et MovedPoint ??

Merci à l'avance ..

Répondre

Questions connexes