【问题标题】:Find points of Pinch Gesture找捏手势的点
【发布时间】:2012-04-25 05:04:01
【问题描述】:

我对 UIGestures 很熟悉,但这种特殊的需求让我碰壁了。

问题:如何找到 UIPinchGesture 的起始两点和结束两点?

我必须得到所有这四个点,并且必须在服务器端进行一些计算。

以前有人试过吗?

【问题讨论】:

    标签: iphone uigesturerecognizer


    【解决方案1】:

    使用

    - (CGPoint)locationOfTouch:(NSUInteger)touchIndex inView:(UIView *)view
    

    喜欢

    [gesture locationOfTouch:0 inView:youView]; //first
    [gesture locationOfTouch:1 inView:youView]; //second
    

    【讨论】:

    • 很抱歉。直到我在设备中运行这段代码,一切都很好,我很高兴。但它设备它有一些 sigAbrts。对于 UIPinchGesture UITouch[2] 是通常的值,它是只读的(即没有设置器)。但是当我在 1 处访问索引时,XCode 会说:“超出范围”。 :(
    • 你应该先检查 [gesture numberOfTouches] ,但 PinchGesture 必须有 2 个点
    • 我正在尝试这种方式并且它可以工作,但是当我将手指放在屏幕上时,我的应用程序在带有 SIGABRT 的locationOfTouch:inView: 行崩溃,并且没有消息。知道为什么吗?
    • 非常感谢朋友。像魅力一样工作
    【解决方案2】:
    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
    {
    UITouch *touchPositionOne = [[[event allTouches] allObjects] objectAtIndex:0];
    UITouch *touchPositionTwo = [[[event allTouches] allObjects] objectAtIndex:1];
    CGPoint fps = [touchPositionOne locationInView:self.imageView];
    CGPoint sps = [touchPositionTwo locationInView:self.imageView];
    
    NSLog(@"%@ %@", NSStringFromCGPoint(fps), NSStringFromCGPoint(sps));
    }
    
    
    - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
    {
    UITouch *touchPositionOne = [[[event allTouches] allObjects] objectAtIndex:0];
    UITouch *touchPositionTwo = [[[event allTouches] allObjects] objectAtIndex:1];
    CGPoint fps = [touchPositionOne locationInView:self.imageView];
    CGPoint sps = [touchPositionTwo locationInView:self.imageView];
    
    NSLog(@"%@ %@", NSStringFromCGPoint(fps), NSStringFromCGPoint(sps));
    }
    

    【讨论】:

      【解决方案3】:
      CGPoint point1 = [gestureRecognizer locationOfTouch:0 inView:piece];
      CGPoint point2 = [gestureRecognizer locationOfTouch:1 inView:piece];
      CGPoint center = [gestureRecognizer locationInView:piece];
      

      【讨论】:

      • 谢谢。但我早就想出了一个解决方案。请在上面找到答案。
      【解决方案4】:

      我认为在 XCode 12 中您可以使用 location(ofTouch:, in:) 来识别点的位置:

      print(sender.location(ofTouch: 0, in: view))
      print(sender.location(ofTouch: 1, in: view))
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-12-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-12-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多