Resolved Detecting sequential touch in a view

Discussion in 'iOS Programming' started by potash, Aug 18, 2011.

  1. potash, Aug 18, 2011
    Last edited: Aug 18, 2011

    potash macrumors newbie

    Joined:
    Jun 16, 2011
    #1
    Hi, I have subclassed a view and implemented its touchesBegan() method to detect a touch event. I'm able to detect multi-touch event in this way. But I couldn't detect a sequential touch. That is, when I press the screen (I get an event for the first touch) without releasing the first finger, and follow up by pressing the screen again in another location with a second finger, the second touch did not generate an event. Is there a way to get an event for the second touch?
     
  2. jnoxx macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #2
    Why don't you use the UITapRecgonizer? or UILongTapgesturerecognizer (or something).
     
  3. potash thread starter macrumors newbie

    Joined:
    Jun 16, 2011
    #3
    It's not really a tap gesture I'm trying to detect. My situation is I have the movement buttons on one side, and actions buttons on the other side. The movement button is pressed and hold to move the character, once button is released the movement stop. While there is movement, an action button can be pressed. Both type of buttons work independently of each other.
     
  4. ArtOfWarfare macrumors G3

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #4
    I made a really simple program that counts how many touches are on the screen a while back:

    Code:
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        self.view.userInteractionEnabled = YES;
        self.view.multipleTouchEnabled = YES;
    }
         
    - (BOOL)canBecomeFirstResponder
    {
        return YES;
    }
    
    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
    {
        touchCounterLabel.text = [NSString stringWithFormat:@"%d", ([touchCounterLabel.text intValue] + [touches count])];
    }
    
    - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
    {
        touchCounterLabel.text = [NSString stringWithFormat:@"%d", ([touchCounterLabel.text intValue] - [touches count])];
    }
    
    - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
    {
        touchCounterLabel.text = [NSString stringWithFormat:@"%d", ([touchCounterLabel.text intValue] - [touches count])];
    }
    This works perfectly... so if you modify what I've posted to actually receive the position of the touches, it should be able to tell whether each button is being pressed or not.

    Oh, potential issue your code has now that I think of it, what if you set the exclusiveTouch property of the view to NO? I know the documentation says the default value is already NO, but it's been wrong before.
     
  5. potash thread starter macrumors newbie

    Joined:
    Jun 16, 2011

Share This Page