title: Animate with scrollview
body: <p>I am trying to animate the position of 2 buttons on a scroll view I have.</p>
  
  <p>My scrollview has 2 views, an inbox showing messages and a user button showing the user settings/profile.</p>
  
  <p>What I am trying to accomplish is a smooth animation with the scrollview. I have detected the scrollviews content offset and call the animation based on the position of the scrollview inside <code>scrollViewDidScroll</code></p>
  
  <p>I have the animation partially working however I dont want to animate with duration I want to animate based on the scroll position so that the buttons move with the scroll (either to the left or the right).</p>
  
  <pre><code>if currentX &lt; width {
      print("This is the message screen")
  
      self.msgIconRightConstraint.constant = scrollView.bounds.width/2 - 15
      self.profileIconRightConstraint.constant = 10
  
      UIView.animate(withDuration: 3, animations: {
          self.view.layoutIfNeeded()
      }, completion: nil)
  
  } else {
      print("This is the settings screen")
  
      self.msgIconRightConstraint.constant = scrollView.bounds.width - 45
      self.profileIconRightConstraint.constant = scrollView.bounds.width/2 - 15
  
      UIView.animate(withDuration: 3, animations: {
          self.view.layoutIfNeeded()
      }, completion: nil)
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/YKJL5l.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YKJL5l.png" alt="enter image description here"></a></p>