【问题标题】:How do you get multiple touch buttons to work with touchesBegan/Moved?如何让多个触摸按钮与 touchesBegan/Moved 一起使用?
【发布时间】:2010-02-18 04:30:38
【问题描述】:

我有一堆按钮,我想以三种不同的方式激活它们。

  1. 着陆
  2. Touch Down - 多点触摸(同时)
  3. 触摸向内拖动(与在钢琴上拖动手指相同)

前两个在 IB 中显然很容易。然而,包括我自己在内的很多人在使用 Touch Drag 时遇到了麻烦。所以我最终使用了- (void) touchesMoved [见代码]。这非常适合拖动......但要让它工作,我必须禁用 IB 中的“用户交互”按钮。这意味着我失去了“Touch Down”和多点触控功能。

所以,为了让“Touch Down”工作,我使用了 -(void) touchesBegan [参见代码]。这工作正常,但我无法让多点触控工作。

有谁知道如何让我的按钮在多点触控期间同时触发?
或者......有没有办法让 IB 中的触摸移动和按钮功能协同工作?

我已经尝试过touch.view.multiTouchEnabled = Yes;,并确保我的按钮在 IB 中可以进行多次触控...但没有。

下面是我的代码。 非常感谢您的帮助。

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [[event touchesForView:self.view] anyObject];

    CGPoint location = [touch locationInView:touch.view];

    if(CGRectContainsPoint(p1.frame, location)) 
    {
        if (!p1.isHighlighted){
            [self pP01];
            [p1 setHighlighted:YES];
    }
}else {
        [p1 setHighlighted:NO];
    }
    //
    if(CGRectContainsPoint(p2.frame, location)) 
    {
        if (!p2.isHighlighted){
            [self pP02];
            [p2 setHighlighted:YES];
        }
    }else {
        [p2 setHighlighted:NO];
    }
    if(CGRectContainsPoint(p3.frame, location))
    {
        if (!p3.isHighlighted){
            [self pP03];
            [p3 setHighlighted:YES];
        }
    }else {
        [p3 setHighlighted:NO];
    }
}

///

- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
    {
        UITouch *touch = [[event touchesForView:self.view] anyObject];
        CGPoint location = [touch locationInView:touch.view];

        if(CGRectContainsPoint(p1.frame, location))
        {
            [self pP01];
            [p1 setHighlighted:YES];
        }
        if(CGRectContainsPoint(p2.frame, location))
        {
            [self pP02];
            [p2 setHighlighted:YES];
        }
        if(CGRectContainsPoint(p3.frame, location))
        {
            [self pP03];
            [p3 setHighlighted:YES];
        }
}

【问题讨论】:

    标签: iphone interface-builder button multi-touch touchesmoved


    【解决方案1】:

    您需要检查每次触摸而不是随机触摸。所以,for(UITouch *t in touches) 而不是 UITouch *touch = [touches anyObject]

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-12-06
      • 1970-01-01
      • 2012-01-17
      • 1970-01-01
      • 1970-01-01
      • 2016-10-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多