In my app when I am switching views with an animation using UIView animations, it works fine the first time when I switch views because the view slides properly into place and everything works. But if I switch back to my original view and then go BACK to the new view, it does not show anything, the view is black but I know my method is getting called.
My code is below, but does anyone see anything that is wrong?
-(void)changeView2ToView3 {
[view2.view.superview addSubview:view3.view];
[view3.view setFrame:CGRectMake(0, kHeight, kWidth, kHeight)];
[UIView animateWithDuration:0.75
animations:^{
[view3.view setFrame:CGRectMake(0, 0, kWidth, kHeight)];
}
completion:^(BOOL finished){
[view2.view removeFromSuperview];
}];
}
kHeight and kWidth are the height and width of the screen and they are never 0 or nil.
Thanks!
After the first time, view2.view’s superview must be nil. So you have to set a variable for saving the superview.