【发布时间】:2016-07-24 22:23:48
【问题描述】:
我需要处理 UITouchTypeStylus 触摸事件的特定操作,并在视图中对按钮进行特定操作。
如果我用苹果铅笔点击按钮,两个事件都会被触发。
告诉我,当用苹果铅笔点击按钮时,如何只触发 UITouchTypeStylus 触摸事件? 要么 如果我们触摸按钮或任何动作如何处理..即使是手写笔。
【问题讨论】:
标签: ios touch stylus stylus-pen
我需要处理 UITouchTypeStylus 触摸事件的特定操作,并在视图中对按钮进行特定操作。
如果我用苹果铅笔点击按钮,两个事件都会被触发。
告诉我,当用苹果铅笔点击按钮时,如何只触发 UITouchTypeStylus 触摸事件? 要么 如果我们触摸按钮或任何动作如何处理..即使是手写笔。
【问题讨论】:
标签: ios touch stylus stylus-pen
最好的方法是使用覆盖 touchesBegan/Moved/Ended 方法和块或委托方法来调用传递触摸类型的 UIButton 子类。然后检查触摸类型并调用相应的功能。
【讨论】:
(void) touchesBegan: (NSSet*) touches withEvent: (UIEvent*) event
{
UITouch* touch = [touches anyObject];
if ([touch type] == UITouchTypeStylus)
{
//your code...
}
else
{
return;
}
[super touchesBegan: touches withEvent: event];
}
【讨论】: