你如何获得多个触摸按键具有的touchesBegan工作/移动? [英] How do you get multiple touch buttons to work with touchesBegan/Moved?

查看:125
本文介绍了你如何获得多个触摸按键具有的touchesBegan工作/移动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一堆,我想在三种不同的方式来激活按钮。


  1. 触摸向下

  2. 接触下来 - 多次接触(在同一时间)

  3. 触摸拖动内(同为过钢琴拖动手指)

前两个是IB明显容易。然而,许多人,包括我自己,曾与内触摸拖拽的麻烦。所以,我结束了使用 - (无效)touchesMoved [见code]。这对于拖动的伟大工程......但要得到它的工作,我不得不禁用IB的按钮用户交互。这意味着我失去了降落和多点触控功能。

因此​​,为了获得触地的工作,我用 - (空)的touchesBegan [见code]。这工作得很好,但我不能让多点触控工作。

有谁知道我能得到我的按钮式多点触摸期间同时火?结果
或...有没有办法让触摸移动和按键功能在IB一起工作?

我曾尝试 touch.view.multiTouchEnabled =是; ,我已确保我的按钮是多个触摸OK在IB ...但没有什么

下面是我的code。
非常感谢你的帮助。

   - (无效)touchesMoved:(*的NSSet)触及withEvent:方法(*的UIEvent)事件
{
    UITouch *触摸= [[事件touchesForView:self.view] anyObject]    CGPoint位置= [触摸locationInView:touch.view];    如果(CGRectContainsPoint(p1.frame,位置))
    {
        如果(!p1.isHighlighted){
            [个体经营PP01]
            [P1 setHighlighted:YES];
    }
}其他{
        [P1 setHighlighted:NO];
    }
    //
    如果(CGRectContainsPoint(p2.frame,位置))
    {
        如果(!p2.isHighlighted){
            [个体经营PP02]
            [P2 setHighlighted:YES];
        }
    }其他{
        [P2 setHighlighted:NO];
    }
    如果(CGRectContainsPoint(p3.frame,位置))
    {
        如果(!p3.isHighlighted){
            [个体经营PP03]
            [P3 setHighlighted:YES];
        }
    }其他{
        [P3 setHighlighted:NO];
    }
}

///

   - (空)的touchesBegan:(*的NSSet)触及withEvent:方法(*的UIEvent)事件
    {
        UITouch *触摸= [[事件touchesForView:self.view] anyObject]
        CGPoint位置= [触摸locationInView:touch.view];        如果(CGRectContainsPoint(p1.frame,位置))
        {
            [个体经营PP01]
            [P1 setHighlighted:YES];
        }
        如果(CGRectContainsPoint(p2.frame,位置))
        {
            [个体经营PP02]
            [P2 setHighlighted:YES];
        }
        如果(CGRectContainsPoint(p3.frame,位置))
        {
            [个体经营PP03]
            [P3 setHighlighted:YES];
        }
}


解决方案

您需要检查每一个接触,而不是一个随意触摸。因此,为(UITouch *在触摸T)而不是 UITouch *触摸= [触摸anyObject]

I have a bunch of buttons that I want to activate in three different ways.

  1. Touch Down
  2. Touch Down - multiple touch (at the same time)
  3. Touch Drag Inside (The same as dragging your finger over a piano)

The first two is obviously easy in IB. However many people, including myself, have had trouble with Touch Drag inside. So I ended up using - (void) touchesMoved [see code] . This works great for the drag... but to get it to work I had to disable the buttons "user Interaction" in IB. Which means I lost the "Touch Down" and multi-touch capabilities.

So, in order to get the "Touch Down" to work, I used -(void) touchesBegan [see code]. This works fine, but I can't get multi-touch to work.

Does anyone know how I can get my buttons to fire simultaneously during multi-touch?
Or ... Is there a way to get touches moved and button functions in IB to work together?

I have tried touch.view.multiTouchEnabled = Yes; and I have ensured that my buttons are multiple touch ok in IB... But nothing.

Below is my code. Thank you very much for your help.

-(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];
        }
}

解决方案

You need to check every touch instead of one random touch. So, for(UITouch *t in touches) instead of UITouch *touch = [touches anyObject]

这篇关于你如何获得多个触摸按键具有的touchesBegan工作/移动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆