thura oo thura oo - 1 year ago 123
Swift Question

Track UIScrollView contentOffset all the time

I'm using a timer and print the

of a
to track it all the time.

But the problems is
updates its
value only after it is decelerated.

I want to know the
value in every millisecond of timer and how can I do that? If I cannot use
of the
at all, is there any other way to track similar value to
of a scrollView?

I'm using swift. Thank you.

Answer Source

Instead of tracking the changes by polling with a timer, you can observe any changes to the value. UIScrollView has a delegate property that gets called for scroll events (see UIScrollViewDelegate), and contentOffset is KVO compliant.

Or you could subclass UIScrollView and try overriding the setters (either for contentOffset or bounds where origin is the the offset, I'm not sure which one, if either, the class calls internally - using the delegate is the preferred solution).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download