2012-06-23 79 views
0

我正在使用這樣的代碼來呈現一個新的視圖,我不好或不好。目前默認動畫是從下向上顯示視圖,但我希望它從右到左(飛入)動畫,是否可以更改默認動畫類型以及如何?謝謝。iphone dev:如何控制視圖過渡動畫?

[self presentModalViewController:navController animated:animated]; 

回答

1

您可以禁用滑動畫這樣的:

[self presentModalViewController:navController animated:NO]; 

然後你可以提供自己的動畫代碼:

navController.view.frame = CGRectMake(320, 0, navController.view.frame.size.width, navController.view.frame.size.height); 

[UIView beginAnimations:nil context:nil]; 
[UIView setAnimationDuration:0.5]; 
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; 
navController.view.frame = CGRectMake(0, 0, navController.view.frame.size.width, navController.view.frame.size.height); 
[UIView commitAnimations]; 

這個例子給你「飛入「從正確的速度曲線。

另一種方法是使用內置的幻燈片,從右側與navigationcontroller:

[self.navigationController pushViewController:navController animated:YES]; 

在這其中,你的頂視圖控制器需要有一個UINavigationController,它的rootcontroller必須是你的ViewController。然後你可以推動其他視圖控制器。

+0

感謝大家好,但我想知道的是最有效使用從右到左飛的iPhone應用程序,是它提供的功能的系統呢? –

+0

是的,將編輯答案 – JulenissensHjelper

+0

謝謝我正在嘗試。 –

0

我已經這樣做了,其工作對我來說嘗試的部份:

[UIView beginAnimations:nil context:nil]; 
      [UIView setAnimationDuration:0.6]; 
      [UIView setAnimationDelegate:self]; 
      [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.View2.superview cache:YES]; 
      [self.View2 removeFromSuperview]; 
      [self performSelector:@selector(replaceViews2) withObject:nil afterDelay:0.6]; 
      [UIView commitAnimations];