【问题标题】:Scrollview only detect scrolling from certain areas?Scrollview 只检测特定区域的滚动?
【发布时间】:2017-02-05 22:35:41
【问题描述】:

我想要一个覆盖整个屏幕的滚动视图。但是我想知道是否可以只允许从部分滚动视图中检测到滚动。例如,您有一个全屏滚动视图,屏幕的上半部分应该检测到滚动,但下半部分不应该检测到滚动。我知道如果您将 alpha 更改为 0,则滚动视图不再滚动,可能的解决方案是更改部分滚动视图的 alpha 吗?这甚至可能吗?有什么想法或想法吗?

【问题讨论】:

  • 一个简单的解决方案是将表格视图添加到 ViewController 并在表格视图中您不想允许触摸的部分添加清晰的视图

标签: ios swift scrollview


【解决方案1】:

您可以从 UIScrollView 继承并覆盖方法 touchesShouldBegin。 您应该检查在什么时候触摸并允许它。

class ScrollView: UIScrollView {

    override func touchesShouldBegin(_ touches: Set<UITouch>, with event: UIEvent?, in view: UIView) -> Bool {

        if (touches.first?.location(in: self).y)! > self.bounds.height / 2 {
            // In bottom part
            return true
        }

        // In top part
        return false
    }
}

【讨论】:

  • 这是我目前所拥有的 func touchesShouldBegin(_ touches: Set, with event: UIEvent?, in view: UIView) -> Bool { } 我将如何编写 if 语句检查接触点的位置
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-09-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多