2010-02-24 101 views
2

我有一个UINavigationController有一个可见的导航栏和工具栏。当推动一个控制器(同一个控制器)时,我只想动画内容部分(例如滑动效果),并保持NavigationBar和Toolbar不动画/常量。任何人都可以提供任何建议干净的方式做到这一点?谢谢。UINavigationController自定义过渡动画

回答

1

我手动移动的看法和使用动画块它们的动画:

// Get position of old view controller 
CGPoint center = [oldViewController.view center]; 

// Position new view controller to the right of old one 
[newViewController.view setCenter:CGPointMake(center.x + 320, center.y)]; 

// Animate change 
[UIView beginAnimations:@"myAnimation" context:NULL]; 

// Move old view off screen 
[oldViewController.view setCenter:CGPointMake(center.x - 320, center.y)]; 

// Move new view onto screen 
[newViewController.view setCenter:center]; 

// Set animation delegate to self so that we can detect when animation is complete 
[UIView setAnimationDelegate:self]; 
[UIView setAnimationDidStopSelector:@selector(animationComplete:finished:target:)]; 

// Finish animation block 
[UIView commitAnimations]; 

如果您需要使用您需要导航控制器实际推新的ViewController确保您的动画之后做到这一点已完成,否则旧视图将不会显示。为此,您需要使用setAnimationDelegate方法来获取动画完成时间和传入选择器方法的通知。在同一类中实现上述代码和以下方法:

(void)animationComplete:(NSString *)animationId 
       finished:(BOOL)finished 
       target:(UIView *)target 
{ 
    if([animationId isEqualToString:@"myAnimation"]) 
    { 
    // Push viewcontroller here 
    } 
} 
+0

Thx。它几乎可以工作,除了oldViewController视图在被推入后消失。当动画发生时,旧视图只是一种黑色。你知道如何在推送之后保持oldViewController.view可见吗?这是我添加来设置oldViewController和newViewController的代码。 \t CGPoint center = [self.view center]; \t UIViewController * oldViewController = [self.navigationController topViewController]; NewController * newViewController = [[[NewController alloc] init] autorelease]; [self.navigationController pushViewController:newViewController animated:NO]; – JStay 2010-02-25 02:11:38

+0

在推入新视图控制器之前,您需要结束动画块。也就是说,在[self.navigationController pushViewController:newViewController animated:NO]之前调用[UIView commitAnimations] – pheelicks 2010-02-25 09:09:53

+0

感谢您的回应。在提交之后,我将push移动到了,并且它仍然产生与新视图转换为黑/空视图相同的结果。我在没有推送的情况下尝试了代码,看看旧视图是否转换出来,并且它可以工作,但是一旦我介绍推送,它就会消失。 – JStay 2010-02-25 09:54:28

1

尝试将工具栏作为子视图添加到窗口而不是视图。并限制导航控制器的视图高度,以便它可以看到你的工具栏。现在,如果您推动视图控制器,则导航栏和工具栏将保持无生气/停滞状态。

+0

我想这样做,但它似乎是一个很大的破解。我会试一试,然后回复。谢谢! – JStay 2010-02-26 07:15:48

+0

我试过这个,大部分都适用。我调整了导航控制器高度的第一次尝试,但是当我推动一个模态控制器并解散它时,高度在解散时总是不正确地返回(只能改变viewDidAppear中的高度,这会让我动荡的动画过渡回来)。接下来,我没有使用导航高度,只是叠加了添加到窗口的工具栏,但随后我与模式控制器重叠UP UP b/c窗口中的工具栏位于更高层,然后导航栏继续。不知道热点解决这个动画呢。想法? – JStay 2010-03-05 15:48:02

0

将新UIViewController的navigationItem设置为与当前UIViewController相同。

newViewcontroller.navigationItem = self.navigationItem; 
[self.navigationController pushViewController:recallViewController animated:YES];