【问题标题】:Handle Apple Pencil Touch Event with UITouchTypeStylus使用 UITouchTypeStylus 处理 Apple Pencil 触控事件
【发布时间】:2016-07-24 22:23:48
【问题描述】:

我需要处理 UITouchTypeStylus 触摸事件的特定操作,并在视图中对按钮进行特定操作。

如果我用苹果铅笔点击按钮,两个事件都会被触发。

告诉我,当用苹果铅笔点击按钮时,如何只触发 UITouchTypeStylus 触摸事件? 要么 如果我们触摸按钮或任何动作如何处理..即使是手写笔。

【问题讨论】:

    标签: ios touch stylus stylus-pen


    【解决方案1】:

    最好的方法是使用覆盖 touchesBegan/Moved/Ended 方法和块或委托方法来调用传递触摸类型的 UIButton 子类。然后检查触摸类型并调用相应的功能。

    【讨论】:

      【解决方案2】:
      (void) touchesBegan: (NSSet*) touches withEvent: (UIEvent*) event
      {
          UITouch* touch = [touches anyObject];
          if ([touch type] == UITouchTypeStylus)
          {
              //your code...
          }
          else
          {
              return;
          }
          [super touchesBegan: touches withEvent: event];
      }
      

      【讨论】:

      • 来自审核队列:我可以请求您在源代码周围添加一些上下文。仅代码的答案很难理解。如果您可以在帖子中添加更多信息,这将对提问者和未来的读者都有帮助。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-05-01
      • 1970-01-01
      • 2022-11-08
      • 1970-01-01
      • 1970-01-01
      • 2012-11-01
      • 1970-01-01
      相关资源
      最近更新 更多