ios - 禁用绘图 View 的多点触控

标签 ios uiview touch

我有一个要画线的 View 。当我用两根或更多手指画一条线时,会出现一种奇怪的行为。这就是为什么我想在此 View 上禁用多点触控。

我试过了:

self.drawingView.multipleTouchEnabled = NO;
self.drawingView.exclusiveTouch = YES;

但是没有影响。而我的 touches 方法仍然被调用。 理想情况下,我希望当我尝试用两根手指绘图时,它什么都不做。有解决办法吗?

谢谢:)

最佳答案

在你的触摸方法(开始/移动)中检查屏幕上有多少触摸,只有一个触摸,处理它,否则传递它。 touchesMoved 示例:

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{


if ((touches.count == 1) && ([event allTouches].count == 1)) {
   // handle single finger touch moves here
    ....
} else {
    // If more than one touch, pass it along
    [super touchesBegan:touches withEvent:event];

}

关于ios - 禁用绘图 View 的多点触控,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13219876/

相关文章:

ios - 更改状态属性值可更新UI,但应用程序崩溃,而XCode中没有任何错误报告SwiftUI

ios - 添加 subview 时屏幕失真

ios - CGContextClearRect 导致背景颜色为黑色

javascript - 是否有模拟触摸事件的附加组件或扩展?

ios - 即使应用程序未运行也显示警报

ios - Controller 中的 NSTimer,如何通知 View ?

uiview - 如何获取实际的[UIScreen mainScreen]框架大小?

javascript - jQueryMobile PhoneGap 应用程序上的后退按钮有时无响应

iphone - 如何检测触摸点是否被CALayer的绘制内容包含?

ios - `Debug navigator` 面板中的 XCode 内存分析显示 `CPU usage` 高于 100%