【问题标题】:Show NavigationController in UIViewController在 UIViewController 中显示 NavigationController
【发布时间】:2016-01-18 19:58:56
【问题描述】:

我有一个来自 Cell 的 UICollectionView,它来自另一个带有缩放动画的 UIViewController。我必须用 UINavigationController 嵌入它,但是当它在模拟器中启动时,它不会显示 UINavigationController。问题是什么 ? 感谢帮助。

Screnshot

 override func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
    collectionView.deselectItemAtIndexPath(indexPath, animated: true)

    let cell: PhotoCell = collectionView.cellForItemAtIndexPath(indexPath)as! PhotoCell

    let detailViewController = storyboard?.instantiateViewControllerWithIdentifier("FullPhotoController") as! FullPhotoController
    let attributes = collectionView.layoutAttributesForItemAtIndexPath(indexPath)
    let attributesFrame = attributes?.frame
    let frameToOpenFrom = collectionView.convertRect(attributesFrame!, toView: collectionView.superview)
    transitionDelegate.openingFrame = frameToOpenFrom

    let picture = everypicture[indexPath.row]
    detailViewController.currentpicture = picture
    detailViewController.transitioningDelegate = transitionDelegate
    detailViewController.modalPresentationStyle = .Custom


    presentViewController(detailViewController, animated: true, completion: nil)


}

【问题讨论】:

  • “FullPhotoController”是 UINavigationController 吗?如果不是,你只是在展示一个常规的模态控制器。

标签: ios swift uiviewcontroller uinavigationcontroller


【解决方案1】:

当您使用 StoryboardId 从 Storyboard 引用 ViewController 时,它会忽略它可能嵌入的任何导航视图。因此您必须执行以下操作。为简洁起见,我省略了一些设置代码。

let detailViewController: UIViewController = self.storyboard!.instantiateViewControllerWithIdentifier("FullPhotoController") as! FullPhotoController
let navigationController: UINavigationController = UINavigationController(rootViewController: detailViewController)
navigationController.modalPresentationStyle = .Custom
navigationController.transitioningDelegate = transitionDelegate

self.presentViewController(navigationController, animated: true, completion: nil)

【讨论】:

  • 当我让我有一个 NavigationController 但动画不是缩放动画时,动画是一个显示细节(例如替换)。我可以在那里做什么?
  • 猜测缩放是由 modalPresentationStyle = .Custom 和 transitioningDelegate = transitionDelegate?如果是这样,只需执行您在 detailViewController 上所做的操作,但将其应用于 navigationController。我会更新答案。
  • 如果这是正确答案,请将其标记为已回答并投赞成票。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-09-11
  • 1970-01-01
  • 1970-01-01
  • 2013-04-21
  • 2012-11-26
  • 1970-01-01
相关资源
最近更新 更多