2012-10-20 107 views
0

如何從一個的viewController要等在使用導航控制器淡入淡出效果在使用導航控制器

通常我們推動實現淡入淡出效果:

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

但我想褪色的時候我突然或推動作用.. PLZ建議

+0

參考這個答案鏈接這將幫助你http://stackoverflow.com/questions/2215672/how-to-change-the-push-and-pop-animations-in-a-navigation-based-app – user1548843

回答

0

這不是你想要的確切代碼,但你能得到怎樣的方式做動畫你想

首先必須通過參數NO任何動畫,而push和pop視圖,並不得不給一些自定義動畫喜歡這

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

對於更詳細的答案,使用有道塊看到this answer在其他問題上的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]; 
         }]; 

對於POP:

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

由於@ijordan

其他一些技巧的問題是here

This一個是你使用一個很好的例子,因爲沒有用它來做額外的編碼,因爲它提供了導航控制器動畫的類別。