cocoa - 识别手势的简单方法

标签 cocoa gesture gesture-recognition

您好,我实现了这个功能,我可以手势,但我如何识别哪个手势是什么?例如简单地向左或向右移动?

我的处理代码:

/*this function is made to handel finger gesture and flip the view to other account*/
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{



    FirstViewController *screen = [[FirstViewController alloc] initWithNibName:nil bundle:nil];

    screen.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    screen.myArray = myArray;    
    [self presentModalViewController:screen animated:YES];
    [screen release];

} 

感谢您的回答

最佳答案

嗯,这很大程度上取决于您想要捕获什么手势。如果是简单的捏合、轻扫等操作,那么您可能应该使用 this document 中描述的 Apple 新(3.2 中)便利类之一。 .

使用这些,捕获手势就像在代码中添加如下内容一样简单:

UITapGestureRecognizer *doubleFingerDTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleDoubleDoubleTap:)];
doubleFingerDTap.numberOfTapsRequired = 2;
[self.view addGestureRecognizer:doubleFingerDTap];

然后实现发现手势时处理该手势的方法:

- (void)handleDoubleDoubleTap:(UIGestureRecognizer *)sender {
      //Do something here
}

这将捕获双击。

关于cocoa - 识别手势的简单方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5313980/

相关文章:

android - android中的手势是什么?

android - scaleGestureDetector.getScaleFactor() 在 Android 6.0 中总是返回 1.0

html - 使用 Cocoa Webkit 进行国际化显示前修改 HTML 的方法

macos - 更改 NSTextField 运行时中拼写检查的语言

iphone - Cocoa - 解析 NSMutableArray 时删除/删除项目

Javascript 支持触摸而不阻止浏览器捏合支持

matlab - 使用隐马尔可夫模型的手势识别

ios - 为 NSURLConnection 委托(delegate)保持线程事件

android - 如何将相对布局设置为 ListView 的项目?并检测我的 ListView 上的手势?

html - 有没有一个好的开源谷歌地图风格 <canvas> 图像组件?