0

Scenario:

Horizontally scrolling UIScrollView with reused page views (so that there are only few page viewcontrollers which are being reused similar way like UITableView cells). So that they are able to be updated with new content and reused I need to know exact position of UIScrollView's content view (offset). This works great.

Now I need to implement custom scrolling animation - I mean to programatically move the content view, so that user touches some buttons, and the scroll view scrolls to desired position with this custom animation. The movement can be very quick and very far. I can not use Core Animation for this, as I could not track position during animation (CA reports you only start and end of the movement). So I decided to use CADisplayLink, and calculate each UIScrollView content for each position. This works great too.

The only problem is, that sometimes I see stroboscopic effect - say I am moving the content to the right, and it looks like it is moving to left. If I look at builtin animation within UISCrollView using setContentOffset:animated:, the animation is smooth and nice. Does anyone know, how to get rid of this stroboscopic effect?

Vilém Kurz
  • 3,401
  • 2
  • 34
  • 43
  • I've used a display link before without the effects you describe. The devil's in the details. I'm guessing there's something about your code that's causing it. Post the code that sets up the display link as well as the code that the displayLink calls. – Duncan C Jun 26 '12 at 20:14
  • Before I paste a code, I'd like to state this: I tried to run the animation slowly, and I clearly saw, that it starts nicely, then when the pace of moving the frames gets correlated to screen refresh rate it starts to optically go backwards, and after few moments it again goes nicely till the end of the animation. I even tried to make a graph - on x axis is time, on y is position. Everything is how I want it to be. It really seems to be optical illusion, not code error to me. I am sure it should be compensated programmatically somehow. So - do you still think it is worthy to paste the code? – Vilém Kurz Jun 27 '12 at 08:50
  • one more hint - I forgot to mention, that the animation is of a kind ease in - this means that it starts slowly and gains momentum. I think this might be the problem. – Vilém Kurz Jun 27 '12 at 13:06
  • some more info - I tried to make animation of constant speed (linear, with no accelerationy). Each distance movement needs different speed - short distance low speed, long distance higher speed. Now the wagon-wheel effect happens only on certain speeds - apparently those with some relation to display frame rate. – Vilém Kurz Jun 27 '12 at 19:10
  • In case anyone else finds this SO: logging, profiling, setting the frame rate incorrectly, loading large amount of "content" during ticks, will all produce a strobe effect when using CADisplayLink. The later two being the culprit here I suspect. – Dupes 'n duds Jul 28 '12 at 19:47
  • wonder how can one set frame rate incorrectly, if it is set by CADisplayLink itself? I came to conclusion, that it is given by physics, rather than software fault. Scrolls like butter, so large amount of content is not a problem too, I think. You probably mean problems with not very smooth scrolling? – Vilém Kurz Jul 28 '12 at 20:42
  • "A CADisplayLink object is a timer object that allows your application to synchronize its drawing to the refresh rate of the display." ... refresh rate, not frame rate. You may find http://stackoverflow.com/a/6003385/568461 helpful. Also, when you're dealing with dequeue/enqueue content, you're still "loading" content. A similar strobe effect will occur when using UITableView if, as @Duncan C mentioned, the devils details are incorrectly set. – Dupes 'n duds Jul 31 '12 at 03:02

1 Answers1

0

Most likely your issue is that timestamp is a double and you're assigning it to a float

Floats have 7 digits while Doubles have 15-16 digits.

So in other words you're experiencing data loss. By using double you should see a silky smooth animation.

The Muffin Man
  • 19,585
  • 30
  • 119
  • 191