在UIViewController中显示NavigationController

时间:2016-01-18 19:58:56

标签: ios swift uiviewcontroller uinavigationcontroller

我有一个来自Cell的UICollectionView它来到另一个带有Zoom Animation的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)


}

1 个答案:

答案 0 :(得分:0)

使用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)
相关问题