我想知道是否有任何方法可以让我在iOS上模拟触摸/点击/压力(按需调用)。我不知道我是否有什么要补充的。。。除了我使用Objective-c进行编码。
我们将感谢您的每一次帮助,提前表示感谢!
编辑:以下是允许我获得所选案例坐标的方法(它在日志中显示):
- (void)collectionViewTableLayoutManager:(DRCollectionViewTableLayoutManager *)manager collectionView:(UICollectionView *)collectionView didSelectCellAtRow:(NSUInteger)row column:(NSUInteger)column indexPath:(NSIndexPath *)indexPath
{
NSLog(@"SELECTED: %ld.%ld / %ld.%ld", (long)indexPath.section, (long)indexPath.row, (long)row, (long)column);
}
以下是我处理PostIt的dragNdrop的方法(请参阅评论中的更多信息):
-(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];
}
下面是我解决问题的方法。最初,处理postIt的dragNdrop的方法在postIt.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];
}