带有NavigationController的PresentViewController

时间:2017-09-11 15:55:31

标签: ios swift3 uinavigationcontroller presentviewcontroller

enter image description here我们要求使用具有以下功能的navigationcontroller来呈现ViewController:

  • 用户应该能够在呈现的视图控制器中导航并维护导航堆栈。
  • 带有导航栏的View Controller只能获得75%的屏幕区域。

为实现这一目标,我们提出了一个带有新ViewController的navigationController作为根视图控制器。

@IBAction func openModal(_ sender: Any) {
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let pvc = storyboard.instantiateViewController(withIdentifier: "ViewControllerA") as UIViewController

        pvc.modalPresentationStyle = UIModalPresentationStyle.custom
        pvc.transitioningDelegate = self as? UIViewControllerTransitioningDelegate
        let navController = UINavigationController(rootViewController: pvc) // Creating a navigation controller with VC1 at the root of the navigation stack.
        self.present(navController, animated:true, completion: nil)
    }

 func presentationController(forPresented presented: UIViewController, presenting: UIViewController?, source: UIViewController) -> UIPresentationController? {
        return HalfSizePresentationController(presentedViewController: presented, presenting: presentingViewController)
    }

但不知怎的,弹出窗口显示在半屏幕上。

如果我们将展示pvc(没有NavigtaionController的ViewController),那么它可以很好地工作。

self.present(pvc, animated: true, completion: nil)

请建议使用navigationController实现相同功能。

0 个答案:

没有答案