如何在 iOS 上模拟触摸
How to simulate a touch on iOS
我想知道是否有任何方法可以让我在 iOS 上模拟 touch/click/pressure(随意调用)。
我不知道我是否有什么要补充的......除了我正在用 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 和 "simulate" 的 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];
}
我想知道是否有任何方法可以让我在 iOS 上模拟 touch/click/pressure(随意调用)。 我不知道我是否有什么要补充的......除了我正在用 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 和 "simulate" 的 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];
}