Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在iOS上模拟触摸_Ios_Objective C_Touch_Simulate - Fatal编程技术网

如何在iOS上模拟触摸

如何在iOS上模拟触摸,ios,objective-c,touch,simulate,Ios,Objective C,Touch,Simulate,我想知道是否有任何方法可以让我在iOS上模拟触摸/点击/压力(可以随意调用)。 我不知道我是否有什么要补充的。。。除了我用Objective-c编码 我们将感谢您的帮助,提前感谢 编辑: 下面是一种方法,允许我获得所选案例的坐标(它在日志中显示): 以下是我处理帖子dragNdrop的方法(有关更多信息,请参见评论): 这就是我解决问题的方法。最初,处理posit的dragNdrop的方法是posit.m。所以我把它移到了我的viewController.m中。现在,通过这种方法,我可以选择vi

我想知道是否有任何方法可以让我在iOS上模拟触摸/点击/压力(可以随意调用)。 我不知道我是否有什么要补充的。。。除了我用Objective-c编码

我们将感谢您的帮助,提前感谢

编辑: 下面是一种方法,允许我获得所选案例的坐标(它在日志中显示):

以下是我处理帖子dragNdrop的方法(有关更多信息,请参见评论):


这就是我解决问题的方法。最初,处理posit的dragNdrop的方法是posit.m。所以我把它移到了我的viewController.m中。现在,通过这种方法,我可以选择viewController的CollectionView并“模拟”单击

下面是我的新方法的外观:

-(IBAction)handlePan:(UIPanGestureRecognizer *)recognizer{
CGPoint translation = [recognizer translationInView:self.view];
recognizer.view.center = CGPointMake(recognizer.view.center.x + translation.x, recognizer.view.center.y + translation.y);

//the coordinates of the drop
if(recognizer.state == UIGestureRecognizerStateEnded){
    CGPoint centerPointOfView = [recognizer locationInView:self.view];
    NSLog(@"X - %f, Y - %f",centerPointOfView.x,centerPointOfView.y);

    //Here is how I pick up the cell where the post it has been dropped
    [_collectionView cellForItemAtIndexPath:[_collectionView indexPathForItemAtPoint:centerPointOfView]];

    NSIndexPath *indexPath =[_collectionView indexPathForItemAtPoint:centerPointOfView];

//some log tests
    NSLog(@"SELECTED: %ld.%ld ", (long)indexPath.section, (long)indexPath.row);
}


[recognizer setTranslation:CGPointMake(0, 0) inView:self.view];
}

你到底想做什么?所以,我有一个对象(一个posit,来自我的nib selectposit.xib)。这个是拖拉的。然后我有一个包含多个案例的集合视图。当我选择其中一个案例时,它会向我返回这个案例的坐标(这允许我识别有问题的案例)。当我拖放帖子时,我还可以得到帖子的最后一个坐标(实际上是拖放的坐标)。我想做的是,当我在一个案例中放置一个帖子时,它将模拟一次点击,点击的坐标将显示我在哪一个案例中放置了帖子。所以你想在点击时调用方法吗?通常你用Interface Builder中的iAction连接你的可点击对象。但是没有什么可以阻止在拖放完成时直接调用iAction方法。只需确定使用了哪个集合项,并将其作为发送方传递给IBActioncall方法,如下所示[buttonDown addTarget:self action:@selector(quantityDown:)forControlEvents:uicontrolEventTouchInside];和-(void)quantityDown:(id)发送方{NSLog(@“%d”,sender.tag);}
-(IBAction)handlePan:(UIPanGestureRecognizer *)recognizer{
CGPoint translation = [recognizer translationInView:self];
recognizer.view.center = CGPointMake(recognizer.view.center.x + translation.x, recognizer.view.center.y + translation.y);

//Here to know the coordinates of the drop
if(recognizer.state == UIGestureRecognizerStateEnded){        
    CGPoint centerPointOfView = [recognizer locationInView:self.superview];
    NSLog(@"X - %f, Y - %f",centerPointOfView.x,centerPointOfView.y);
}

[recognizer setTranslation:CGPointMake(0, 0) inView:self];
}
-(IBAction)handlePan:(UIPanGestureRecognizer *)recognizer{
CGPoint translation = [recognizer translationInView:self.view];
recognizer.view.center = CGPointMake(recognizer.view.center.x + translation.x, recognizer.view.center.y + translation.y);

//the coordinates of the drop
if(recognizer.state == UIGestureRecognizerStateEnded){
    CGPoint centerPointOfView = [recognizer locationInView:self.view];
    NSLog(@"X - %f, Y - %f",centerPointOfView.x,centerPointOfView.y);

    //Here is how I pick up the cell where the post it has been dropped
    [_collectionView cellForItemAtIndexPath:[_collectionView indexPathForItemAtPoint:centerPointOfView]];

    NSIndexPath *indexPath =[_collectionView indexPathForItemAtPoint:centerPointOfView];

//some log tests
    NSLog(@"SELECTED: %ld.%ld ", (long)indexPath.section, (long)indexPath.row);
}


[recognizer setTranslation:CGPointMake(0, 0) inView:self.view];
}