菜鸟教程小白 发表于 2022-12-12 14:01:18

ios - 如何从起点和滚动点查找端点坐标


                                            <p><p>我必须从起点和移动点找到端点。</p>

<p>我正在制作动画,当用户拖动 View 时我需要移动 <code>View</code> 然后我必须将其从屏幕中移出并返回原点。</p>

<p>现在我使用 <strong>UISwipeGestureRecognizer</strong> 来检测 Move 上的滑动。以下是代码。</p>

<pre><code> UISwipeGestureRecognizer *swipeLeft = [ initWithTarget:self action:@selector(handleSwipe:)];
    UISwipeGestureRecognizer *swipeRight = [ initWithTarget:self action:@selector(handleSwipe:)];
    UISwipeGestureRecognizer *swipeUp = [ initWithTarget:self action:@selector(handleSwipe:)];
    UISwipeGestureRecognizer *swipeDown = [ initWithTarget:self action:@selector(handleSwipe:)];

    // Setting the swipe direction.
    ;
    ;
    ;
    ;

    // Adding the swipe gesture on image view
    ;
    ;
    ;
    ;
</code></pre>

<p><strong>处理滑动</strong> </p>

<pre><code>- (void)handleSwipe:(UISwipeGestureRecognizer *)swipe {

    CGPoint movedPoint = ;

    if (swipe.direction == UISwipeGestureRecognizerDirectionLeft) {
      NSLog(@&#34;Left Swipe&#34;);

      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(@&#34;Right Swipe&#34;);
      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(@&#34;Up Swipe&#34;);

      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(@&#34;Down Swipe&#34;);

      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) {

            }];
      }];
    }

}
</code></pre>

<p> <img src="/image/mMaL6.png" alt="enter image description here"/> </p>

<p>当我滑动第一 View 时,我可以在 <strong>SwipeHandler</strong> (handleSwipe) 方法中移动点</p>

<p>所以我也可以检测滑动方向。但我的问题是我必须通过No.1 View 走出屏幕。为此,我必须找到端点。</p>

<p>那么,如何从起点和移动点找到端点?</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>这里是端点计算的链接。 <a href="http://library.thinkquest.org/20991/geo/coordgeo.html" rel="noreferrer noopener nofollow">http://library.thinkquest.org/20991/geo/coordgeo.html</a> </p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 如何从起点和滚动点查找端点坐标,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/18569570/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/18569570/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 如何从起点和滚动点查找端点坐标