title: Two simultaneous scroll views behaving weirdly
body: <p>I'm trying to implement a design like Twitter homepage on iOS, which can be simplified to something like the following:</p>
  
  <p><a href="https://i.stack.imgur.com/Cg785.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Cg785.png" alt="enter image description here"></a></p>
  
  <p>Both scroll views receive gesture through the <code>gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer)</code> method, which works well.</p>
  
  <p>My scrolling logic is the following:</p>
  
  <pre><code>private func parentScrollViewDidScroll(_ scrollView: UIScrollView) {
    if self.parentScrollViewLocked {
      scrollView.contentOffset.y = threshold
      self.childScrollViewLocked = false
      return
    }
  
    if scrollView.contentOffset.y &gt;= threshold {
      scrollView.contentOffset.y = threshold
      self.parentScrollViewLocked = true
      self.childScrollViewLocked = false
    }
  }
  
  private func childScrollViewDidScroll(_ scrollView: UIScrollView) {
    if self.childScrollViewLocked {
      scrollView.contentOffset.y = 0
    } else if scrollView.contentOffset.y &lt;= 0 {
      self.childScrollViewLocked = true
      self.parentScrollViewLocked = false
    }
  }
  </code></pre>
  
  <p>This actually works pretty well. The only problem though is when scrolling down slowly (but still with deceleration), there's a good chance the scroll ends at the threshold, without transitioning from parent scrolling to child scrolling smoothly. When scrolling fast enough, it's pretty smooth and can continue just fine.</p>
  
  <p>What's intriguing is that when scrolling back up, no matter how slow I scroll I don't have any problem at all. Every time it's a smooth transition.</p>
  
  <p>It turns out that for some reason, the child scroll view come to a stop signaled by <code>scrollViewDidEndDecelerating(_ scrollView: UIScrollView)</code> at the threshold - much earlier than the parent view. But the parent view is locked beyond the threshold so it doesn't move, and the child scroll view has already finished, so the scrolling will end there. When scrolling back up both scroll views behave normally, so my logic handles it fine.</p>
  
  <p>What may be wrong here? Any pointer appreciated. Thank you!</p>