简体   繁体   English

如何在iOS 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. 我目前在屏幕上有两个按钮,一个在左边,一个在右边,我想知道iOS Simulator是否有一种方法可以模拟同时按下两个按钮。 I tried pressing ⌥ Alt on the simulator as a result two circles appear. 我尝试在模拟器上按⌥Alt ,结果出现了两个圆圈。 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. 我可以在左侧的第一个按钮上放置一个圆圈,但是我不确定如何在右侧的按钮上放置下一个圆圈。

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. 有了两个圆圈(使用Alt键)后,将两个圆圈一起移动,然后按住Shift键:这将允许您将两个圆圈移动到模拟器屏幕上的任意位置。

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. 并按预期工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM