Search code examples
iosswiftcocoa-touchuiscrollviewuiscrollviewdelegate

Stop an object in UIScrollView from moving


Is there a way to stop an object in a UIScrollView from moving as a result of the UIScrollView responding from user interaction? Essentially I want some things in the scrollview to move but others to remain frozen in place. They all need to be within the scrollview, so moving them to a different view is not an option.


Solution

  • For anyone else having the same problem, I found an answer. I put the objects which I wanted to remain still in a UIView. I then used the UIScrollView delegates to get the initial content offset when the scroll was about to begin and subtracted the current content offset as the scroll view was scrolling to get the change in the content offset. Afterwards, I sent that content offset to the container view I put all my objects in and subtracted the change in content offset from the container view's position. The result is everything in the container view remaining perfectly still.