mhillsman
mhillsman

Reputation: 770

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.

Upvotes: 0

Views: 250

Answers (2)

mhillsman
mhillsman

Reputation: 770

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.

Upvotes: 1

Essam Elmasry
Essam Elmasry

Reputation: 1252

add to the desired fixed object a constraint in relation to the main view. This would pin it to that view.

Upvotes: 0

Related Questions