首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >让UIScrollView放弃UITouch

让UIScrollView放弃UITouch
EN

Stack Overflow用户
提问于 2017-10-22 08:45:53
回答 1查看 173关注 0票数 1

我有一个绘图应用程序,它的画布比手机屏幕大小。我想实现两个手指滚动,一个手指作画。到目前为止,我可以使滚动工作正常,但当涉及到绘制时,线开始,然后绘制的视图失去了对触摸的控制,从而只绘制了线的第一部分。我认为scrollview收回了控制权。点可以画得很好。

这是我的子类UIScrollView

代码语言:javascript
复制
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
    guard let touches = event?.touches(for: self) else { return }
    if touches.count < 2 {
        self.next?.touchesBegan(touches, with: event)
    } else {
        super.touchesBegan(touches, with: event)
    }
}

override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
    guard let touches = event?.touches(for: self) else { return }
    if touches.count < 2 {
        self.next?.touchesEnded(touches, with: event)
    } else {
        super.touchesEnded(touches, with: event)
    }
}

override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
    guard let touches = event?.touches(for: self) else { return }
    if touches.count < 2 {
        self.next?.touchesMoved(touches, with: event)
    } else {
        super.touchesMoved(touches, with: event)
    }
}

override func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent?) {
    guard let touches = event?.touches(for: self) else { return }
    if touches.count < 2 {
        self.next?.touchesCancelled(touches, with: event)
    } else {
        super.touchesCancelled(touches, with: event)
    }
}

override func touchesShouldCancel(in view: UIView) -> Bool {
    if (type(of: view)) == UIScrollView.self {
        return true
    }
    return false
}
EN

回答 1

Stack Overflow用户

发布于 2017-10-22 10:04:47

您将需要一个连接到您的ScrollerView的长按手势识别器,设置为最小持续时间0秒,还可以识别only 1 TouchCancel touches in view选项激活。

您可以在Interface Builder上的Attributes Inspector下找到所有这些选项。

请稍微调整一下容差设置以微调结果。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46869483

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档