Subview fades and fades

I have a problem fading my subview. I have no problem fading away, but disappearing. The view is simply reduced.

-(void)flipToReview { ReviewViewController *reviewVariable = [[ReviewViewController alloc] initWithNibName:@"ReviewViewController" bundle:nil]; [self setReviewViewController:reviewVariable]; self.ReviewViewController.view.alpha =0; [UIView beginAnimations:@"flipview" context:nil]; [UIView setAnimationDuration:0.3]; [UIView setAnimationCurve:UIViewAnimationCurveLinear]; [UIView setAnimationTransition:UIViewAnimationTransitionNone forView:_window cache:YES]; [reviewVariable release]; [self.window addSubview:self.ReviewViewController.view]; self.ReviewViewController.view.alpha =1; [UIView commitAnimations]; } -(void)flipBackFromReview { // self.ReviewViewController.view.alpha = 1; [UIView beginAnimations:@"trip" context:nil]; [UIView setAnimationDuration:0.3]; [UIView setAnimationCurve:UIViewAnimationCurveLinear]; [UIView setAnimationTransition:UIViewAnimationTransitionNone forView:_window cache:NO]; self.ReviewViewController.view.alpha = 0; [self.ReviewViewController.view removeFromSuperview]; [UIView commitAnimations]; self.window.rootViewController = self.tabBarController; [self.window makeKeyAndVisible]; [self.ReviewViewController.view setHidden:1]; NSLog(@"remove subview"); } 
+4
source share
3 answers

You need to move:

 [self.ReviewViewController.view removeFromSuperview]; 

This cannot be done "over time" in the animation. What you want to do is move this to the selector and use setAnimationDelegate and setAnimationDidStopSelector . Add the following to the animation block:

 [UIView setAnimationDelegate:self]; [UIView setAnimationDidStopSelector:@selector(finshedFadeOut)]; 

Then do the following method:

 - (void)finshedFadeOut { [self.ReviewViewController.view removeFromSuperview]; } 
+3
source

Try the following:

 [UIView animateWithDuration:3.0 delay:0.0 options:UIViewAnimationOptionAllowUserInteraction animations:^{ ReviewViewController.view.alpha = 0.0;} completion:^(BOOL fin) { if (fin) [ReviewViewController.view removeFromSuperview]; }]; 
+7
source

I had this problem too, since I got around this, changing the alpha to 0, and not just deleting the view. It can be animated.

+1
source

All Articles