开发者

Subview fade in and fade out help

I am having a problem fading out my subview. I have no trouble fading the view in but fading out ..just drops the view.

-(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 setAnimatio开发者_如何学JAVAnCurve: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"); 
}


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];
                 }];


You need to move:

[self.ReviewViewController.view removeFromSuperview];

That cannot be done "over time" in an animation. What you want to do is move that to a selector and use setAnimationDelegate and setAnimationDidStopSelector. Put the following in your animation block:

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

Then make the following method:

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


I had this issue as well, the way I got around it was changing the alpha to 0, instead of just removing the view. That can be animated.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜