0

I have 2 identical views on top of each other. One is a real one and one is supposed to act as a dummy.

I'd like to crossfade between them (silently). I set one view's alpha to 0 and second view's alpha to 1 simultaneously in the same animation block.

But the results are not smooth and I'm able to see one view is fading out while the second one is fading in. I'd like this animation to be silent (i.e without any animation at all).

P.S. I cannot just set those alphas without any animation, because the real view is a part of the collection view which has to fade out and the second view (dummy) supposes to substitute one of collection view's cells after the collection view is gone.

Any way to do it and why iOS renders it that way?

Thanks!

user-123
  • 874
  • 1
  • 13
  • 34

1 Answers1

2

Try:

[UIView transitionFromView:view1 toView:view2 duration:0.5
                       options:UIViewAnimationOptionTransitionCrossDissolve
                    completion:^(BOOL finished) {
        // Compeltion code
    }];
Aviel Gross
  • 9,770
  • 3
  • 52
  • 62
  • Thanks! Worked like a charm. – user-123 Mar 04 '14 at 12:41
  • One question: this line removes view1 from the view hierarchy if I understand correctly. How do I make this animation later in reverse? – user-123 Mar 04 '14 at 13:45
  • This removes view1 from it's superView, resulting that if no one has a strong reference to it it will get dealloc. You can hold that view in the class level and later perform the same transition, this time `fromView:view2 toView:savedView` – Aviel Gross Mar 04 '14 at 13:57