子视图淡入并淡出帮助

时间:2011-05-20 19:32:27

标签: iphone objective-c cocoa-touch uiview

我有一个问题淡出我的子视图。我可以毫不费力地淡出视图但是渐渐消失。只是放下视图。

-(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"); 
}

3 个答案:

答案 0 :(得分:7)

尝试以下方法:

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

答案 1 :(得分:3)

你需要搬家:

[self.ReviewViewController.view removeFromSuperview];

动画中无法“随时间推移”。您要做的是将其移至选择器并使用setAnimationDelegatesetAnimationDidStopSelector。将以下内容放在动画块中:

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

然后制作以下方法:

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

答案 2 :(得分:1)

我也遇到过这个问题,我解决这个问题的方法是将alpha更改为0,而不是仅删除视图。这可以动画。