Previous view flickers
tobe-sta opened this issue · 5 comments
I have a sequence controlled, forward direction flipView. When I change the flipView, at the end of the animation, it flickers the previous view that I was just on. I notice it occasionally happens on your demo app too. Is there a way to prevent that from happening?
Thanks for any help.
Yes I've also noticed some flickering, it appears more serious on the simulator and on older devices. I'm not very sure what is the exact cause, but likely due to one or more of the below:
- z-index crossing when I reset the perspective transform
- view reverting to its original state (showing the untransformed view for a split second) at the end of the animation loop
- incorrect usage of CAMediaTiming fillmode in the animation loop (theoretically fill mode both and forwards are supposed to freeze the transform values at the end of the animation loop)
- incorrect usage of CATransaction to reset the animation atomically
The problems should be contained within AnimationDelegate source file, the type of flip animation doesn't matter. I hope to release an update soon to fix the issue (probably going to try switching to GCD for the animation loop), in the meantime you can try editing the AnimationDelegate file
You should be able to fix the flicker by using one or (probably) both of these lines of code:
animation.fillMode = kCAFillModeForwards;
animation.removedOnCompletion = NO;
This will freeze the final animation until you're able to update the underlying views to the new values. Don't forget the remove the animation in the -animationDidStop:finished: callback if you set the -removedOnCompletion flag.
Let me know if you need help getting this working.
Where exactly do you put those two lines? I played around with them in AnimationDelegate, but with no success.
@tobe-sta
the wrapper function - (void)setTransformProgress::::::::::
in AnimationDelegate allows you to specify the fillMode and removedOnCompletion setting, currently all the animations (except for the queued shadow animation in triggered/auto mode) uses kCAFillModeForwards
and removedOnCompletion = NO
@DaveBatton
I think the flickering is due to the removal of animation after completion, whether manually after the callback from animation stopping, or from the removedOnCompletion property. The logic for my animation loop is -
- add transform animation when input is received
- remove animation when animation ends or interrupted by new input (for controlled mode)
- if not at resting position, move to nearest resting position (for controlled mode)
- remove animation when animation ends
- rearrange layers according to whether the flip has progressed or is still on the same frame
For all the areas where the animation is removed, the update has to be committed atomically so that the intermediate changes are not visible. In particular, for the last operation because rearrangement of layers is involved, the rearrangement has to be committed together with the animation removal so that the layer that just completes animating does not show its original state before being replaced by the next layer
I've updated the code to reflect this, let me know if it fixes the issue