iphone - 我应用程序所有屏幕中的字母手势识别

标签 iphone ios ios4 touch gesture

我正在努力检测我的应用程序中的字母手势。所以当用户在屏幕上画一个 C 时,会发生一个特殊的 Action 等等。我正在使用识别器类,该类具有关于每个字母触摸点的预定义数据,并且检测正常。我希望在我的所有屏幕上都有这个功能,所以我将以下方法添加到 appDelegate 类并仅检测窗口中的触摸,这里发生的是屏幕内的其他 View (如 tableview 和 scrollview)阻止触摸事件发送到窗口 - 如果那完美地发生了那么我的代码就会像魅力一样工作。感谢您的帮助。

- (void)processGestureData
   {
     NSString *gestureName = [recognizer findBestMatchCenter:&center angle:&angle   score:&score];
     NSLog(@"gesture Name: %@",gestureName);

     if ([gestureName isEqualToString:@"N"] || [gestureName isEqualToString:@"n"])
     {//handle N gesture
     }

     if ([gestureName isEqualToString:@"C"]) 
     {//handle C gesture
     }

   }


 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
 {
  [recognizer resetTouches];
  [recognizer addTouches:touches fromView:self.window];
 }
 - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
 {
  [recognizer addTouches:touches fromView:self.window];
 }
 - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
 {
  [recognizer addTouches:touches fromView:self.window];

  [self processGestureData];
 }

最佳答案

我认为您需要一些触摸拦截窗口来放置所有触摸。 如果识别出您的手势,则进行处理,否则将触摸传递给您的 View Controller 。引用this link详情

关于iphone - 我应用程序所有屏幕中的字母手势识别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15516364/

相关文章:

iphone - iOS 4 中的多任务感知应用程序和自定义 URL 方案

iPhone 开发者 : any snippet to resize an image and keep the ratio?

iphone - 如何将 UITableView 滚动到特定位置

iphone - 由于不受信任的证书,无法通过 HTTPS 接收 JSON 请求

ios - CAGradientLayer 对角渐变

iphone - UIWebView 中的字体显示不正确

iphone - 展开折叠 UITableViewCell

ios - ScrollView 内的 SwiftUI 列表

ios - 确定用户是否已启用应用程序的 Safari 内容拦截器扩展

ios5 - TouchesEnded 在 iOS5 中不起作用,在 iOS4 中工作正常