0

使用导航控制器从一个视图控制器转到另一个视图控制器时如何实现淡入淡出效果

通常我们会推动:

DetailViewController *obj= [[DetailViewController alloc]initWithNibName:@"DetailView" bundle:nil];
[self.navigationController pushViewController:obj animated:YES];

并弹出:

UINavigationController *navController = self.navigationController;

// retain ourselves so that the controller will still exist once it's popped off
 [[self retain] autorelease];

// Pop this controller and replace with another
[navController popViewControllerAnimated:YES];

但是当我弹出或推送时我想要褪色效果..请建议

4

1 回答 1

0

这不是您想要的确切代码,但您可以获得如何制作您想要的动画的方式

首先必须NO在推送和弹出视图时传递任何动画的参数,并且必须提供一些像这样的自定义动画

// Flash the screen white and fade it out to give UI feedback that a still image was taken
    UIView *flashView = [[UIView alloc] initWithFrame:[[self videoPreviewView] frame]];
    [flashView setBackgroundColor:[UIColor whiteColor]];
    [[[self view] window] addSubview:flashView];

    [UIView animateWithDuration:.4f
                     animations:^{
                         [flashView setAlpha:0.f];
                     }
                     completion:^(BOOL finished){
                         [flashView removeFromSuperview];
                     }
     ];

有关更详细的答案并以正确的方式使用该块,请参阅关于 SO 上其他问题的答案

该答案中的一些代码如下

对于推送:

MainView *nextView = [[MainView alloc] init];
[UIView animateWithDuration:0.75
                         animations:^{
                             [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
                             [super pushViewController:nextView animated:NO];
                             [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.navigationController.view cache:NO];
                         }];

对于流行音乐:

[UIView animateWithDuration:0.75
                         animations:^{
                             [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
                             [UIView setAnimationTransition:transition forView:self.navigationController.view cache:NO];
                         }];
[self.navigationController popViewControllerAnimated:NO];

感谢@jordan

该问题的其他一些提示是here

是一个很好的示例,您无需为此进行额外的编码,因为它为导航控制器的动画提供了类别。

于 2012-10-20T05:53:40.563 回答