UISCrollview和Touchesbegan的问题

发布于 2025-02-08 14:46:14 字数 743 浏览 0 评论 0原文

当用户触摸一个白色Uiviews时,它运行其触摸began:

...

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        delegate.startedTouchingPage(page: self)
        ...

代表是VC。正如I 认为一样,VC在VC中实施了启动TouchingPage

    func startedTouchingPage(page: Page) {
        if (page.tool == .PEN || page.tool == .ERASER) {
            scrollView.isScrollEnabled = false
            scrollView.panGestureRecognizer.isEnabled = false
        }
    }

这将阻止滚动和平移,并让笔画和平。但是,相反,当我尝试在页面上绘制时,笔有时会正确绘制,有时会滚动页面

事实证明,页面滚动而不是绘制的时代,touchesbegan没有运行,因此启动touchingpage也没有运行。我不知道为什么...

When a user touches one of the white UIViews, it runs its touchesBegan:

...

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        delegate.startedTouchingPage(page: self)
        ...

The delegate is the VC. startedTouchingPage is implemented in the VC as

    func startedTouchingPage(page: Page) {
        if (page.tool == .PEN || page.tool == .ERASER) {
            scrollView.isScrollEnabled = false
            scrollView.panGestureRecognizer.isEnabled = false
        }
    }

I thought this would prevent scrolling and panning, and allow the pen to draw in peace. But instead, when I try to draw on the page, the pen sometimes draws properly, and sometimes instead scrolls the page.

It turns out that the times that the page scrolls instead of draws, touchesBegan didn't run, and thus startedTouchingPage didnt run either. I can't figure out why...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文