• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

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

[复制链接]
菜鸟教程小白 发表于 2022-12-12 14:01:18 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我必须从起点和移动点找到端点。

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

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

 UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self actionselector(handleSwipe];
    UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self actionselector(handleSwipe];
    UISwipeGestureRecognizer *swipeUp = [[UISwipeGestureRecognizer alloc] initWithTarget:self actionselector(handleSwipe];
    UISwipeGestureRecognizer *swipeDown = [[UISwipeGestureRecognizer alloc] initWithTarget:self actionselector(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];

处理滑动

- (void)handleSwipeUISwipeGestureRecognizer *)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

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

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

那么,如何从起点和移动点找到端点?



Best Answer-推荐答案


这里是端点计算的链接。 http://library.thinkquest.org/20991/geo/coordgeo.html

关于ios - 如何从起点和滚动点查找端点坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18569570/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap