Search code examples
iosios-simulator

How to simulate simultaneous touch in iOS Simulator


I currently have two buttons on my screen , one on the left and one on the right , I wanted to know if there is a way in the iOS Simulator to simulate both buttons being pressed at the same time. I tried pressing ⌥ Alt on the simulator as a result two circles appear. I can position one circle to the first button on the left however I am not sure how to position the next circle on the right button.


Solution

  • Once you have the two circles (using the Alt key), move the circles together, then hold the shift key: this will allow you to move the two circles anywhere on the simulator screen.

    Then let go the key and click.

    I just tried it with this code:

    -(void)tapTwo:(UITapGestureRecognizer*)recognizer
    {
        CGPoint p1 = [recognizer locationOfTouch:0 inView:self.view];
        CGPoint p2 = [recognizer locationOfTouch:1 inView:self.view];
        NSLog(@"Points: %@ and %@",NSStringFromCGPoint(p1),NSStringFromCGPoint(p2));
    }
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        UITapGestureRecognizer* r = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapTwo:)];
        r.numberOfTouchesRequired = 2;
       [self.view addGestureRecognizer:r];
    }
    

    and it worked as expected.