I am attempting to switch views (XIB’s) while fading through black. I have been doing this using UIView animations and I want to keep it that way. The problem is that whenever I switch views I am not fading through black, its more of a fade directly to the next XIB.
How would I properly do this?
Here is my code (self.view = view1.view in my case, but maybe I shouldn’t do that):
[self.view setBackgroundColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:1.0]];
[UIView animateWithDuration:0.4
animations:^{
[view1.view setAlpha:0];
}
completion:^(BOOL finished){
[self.view.superview addSubview:view2.view];
[view2.view setAlpha:0];
[view2.view setFrame:CGRectMake(0, 0, 320, 480)];
[UIView animateWithDuration:0.4
animations:^{
[view2.view setAlpha:1];
}
completion:^(BOOL finished){
[view1.view removeFromSuperview];
}];
Thanks!
I think your problem is that the background color of self.view is part of that view. When you fade the view, it fades the background too.
Instead, you should put a view that you keep on the screen all the time, that’s empty and has a black background color, and is behind view1 or view2.