【问题标题】:How to create a UINavigationController that pushes from the top of the screen?如何创建从屏幕顶部推送的 UINavigationController?
【发布时间】:2012-12-14 02:23:24
【问题描述】:

我正在创建一个带有标准“Master-Detail”导航的 iPhone 应用程序,您可以在其中从 UITableView 中选择一个项目,然后在 ViewController 中查看推送到屏幕上的项目的详细信息视图。

但是:与传统的 UINavigationController 不同,它从窗口右侧推送详细信息屏幕,我希望我的详细信息屏幕从屏幕顶部向下移动。

我需要什么来完成这项工作?我必须继承 UINavigationController 吗? (我听说这不是一个好主意)。我应该考虑子类化哪些类?

【问题讨论】:

  • 您是否尝试过关闭推送/弹出动画并创建自定义动画?

标签: iphone ios uinavigationcontroller pushviewcontroller


【解决方案1】:

子类 UINavigationController 并覆盖 pushViewController:animated:
不要立即调用 super 并且你自定义动画的东西是这样的:

nextViewController.view.transform = CGAffineTransformMakeTranslation(0, -nextViewController.view.frame.size.height);

void(^animationBlock)(void) = ^{
    [super pushViewController:nextViewController animated:NO];
    nextViewController.view.transform = CGAffineTransformIdentity;
};

if (animated) {
    [UIView animateWithDuration:0.3f animations:animationBlock];
}
else{
    animationBlock();
}

更新:

您实际上不需要继承 UINavigationController。每次将 VC 推送到常规 UINavigationController 时,您也可以执行上述动画操作。

【讨论】:

  • 感谢@Kashiv 和@yinkou!我会试一试。
猜你喜欢
  • 2011-12-25
  • 2016-03-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-10-10
  • 1970-01-01
  • 2011-07-10
  • 2010-11-16
相关资源
最近更新 更多