【发布时间】:2010-02-24 09:33:59
【问题描述】:
我有一个 UINavigationController,它有一个可见的导航栏和工具栏。推送控制器(同一个控制器)时,我只想为内容部分设置动画(例如具有滑动效果),并保持 NavigationBar 和 Toolbar 不动画/恒定。任何人都可以就这样做的干净方式提供任何建议吗?谢谢。
【问题讨论】:
标签: iphone uinavigationcontroller
我有一个 UINavigationController,它有一个可见的导航栏和工具栏。推送控制器(同一个控制器)时,我只想为内容部分设置动画(例如具有滑动效果),并保持 NavigationBar 和 Toolbar 不动画/恒定。任何人都可以就这样做的干净方式提供任何建议吗?谢谢。
【问题讨论】:
标签: iphone uinavigationcontroller
我会手动移动视图并使用动画块对其进行动画处理:
// 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];
如果您需要使用导航控制器实际推送新的视图控制器,您需要确保在动画完成后执行此操作,否则将不会显示旧视图。为此,您需要使用 setAnimationDelegate 方法来获取动画何时完成的通知,并传入要调用的选择器方法。在同一个类中实现上面的代码和下面的方法:
(void)animationComplete:(NSString *)animationId
finished:(BOOL)finished
target:(UIView *)target
{
if([animationId isEqualToString:@"myAnimation"])
{
// Push viewcontroller here
}
}
【讨论】:
尝试将工具栏作为子视图添加到窗口而不是视图。并限制 navigationcontroller 视图高度,以便您可以看到它的工具栏。现在,如果您按下视图控制器,导航栏和工具栏将保持无动画/停滞状态。
【讨论】:
将新 UIViewController 的 navigationItem 设置为与当前 UIViewController 相同。
newViewcontroller.navigationItem = self.navigationItem;
[self.navigationController pushViewController:recallViewController animated:YES];
【讨论】: