nicklockwood / iCarousel

A simple, highly customisable, data-driven 3D carousel for iOS and Mac OS
http://www.charcoaldesign.co.uk/source/cocoa#icarousel
Other
12k stars 2.58k forks source link

Not actual value of scrollOffset? #615

Open gerchicov-bp opened 9 years ago

gerchicov-bp commented 9 years ago

I tried to add custom animation by using the following code:

[UIView animateWithDuration:... animations:^{

                                     [self scrollToItemAtIndex:0 animated:NO];

...

During the animation I need to get the current value of the scrollOffset but I get the "destination" value only. How to solve this issue?

nicklockwood commented 9 years ago

There is no way, I'm afraid. The scrollOffset itself is not being animated if you do this - what's happening is that the scrollOffset is updated immediately, and then Core Animation is animating the positions of all of the carousel views from their old position to the new position.

Scrolling this way will also causes animation glitches if the carousel is nonlinear (e.g. a cylinder) because the views will move in a straight line to their new position, instead of rotating, and if any new views need to be loaded during the animation, you'll see gaps where they should be until the animation ends.

If you need a custom animation, you're probably better off animating it manually using an NSTimer or CADisplayLink to update the scrollOffset each frame (that's how iCarousel works internally).

gerchicov-bp commented 9 years ago

Ok, thanks for advice. Could you additionally explain - maybe it will be easier to temporarily disable velocity attenuation? It means I still couldn't get the current animation values but I could simply calculate them by splitting the distance into the equal pieces.

nicklockwood commented 9 years ago

If you animate the scroll offset using [UIView animateWithDuration:] then there is no velocity attenuation performed by iCarousel itself - the animation is completely controlled by UIKit. If you mean the attenuation applied by the UIView animation, then you disable that by using UIViewAnimationOptionCurveLinear.

gerchicov-bp commented 9 years ago

Sorry I forgot to say. I have found out it is enough for me to get, store and use the initial scroll position so I used the initial casousel methods (scrollToItemAtIndex:) and (scrollToOffset:) but I still can't understand how to disable the acceleration in your code (or how to limit it because it becomes too fast for my app).

nicklockwood commented 9 years ago

Ah, I see. There's current no way to set this without modifying the code. You have to animate it yourself with a timer, then you can use your own timing formula.

gerchicov-bp commented 9 years ago

Could you explain what to do if it is not hard for you? I already have a class which is inherited from iCarousel if you mean this