在 ModalView 中从底部推送 ViewController 全屏
Push ViewController full screen from bottom inside ModalView
在我的应用程序中,我有一个 MainVC
。从那里我 present
另一个 ViewControllerB
我想 push
在那里所以这就是我实现这个的方法:
let ViewControllerB = self.storyboard?.instantiateViewController(withIdentifier: "ViewControllerB") as! ViewControllerB
let navController = UINavigationController(rootViewController: communityVC)
self.present(navController, animated: true, completion: nil)
这正是我想要的效果。然而在
ViewControllerB
我还想 push
某个 ViewControllerC
全屏 来自 底部 而不仅仅是内部modalView
。我这样称呼:
let firstLaunchVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "FirstLaunchVC")
let transition:CATransition = CATransition()
transition.duration = 0.5
transition.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut)
transition.type = CATransitionType.push
transition.subtype = CATransitionSubtype.fromTop
self.navigationController?.modalPresentationStyle = .fullScreen
self.navigationController!.view.layer.add(transition, forKey: kCATransition)
self.navigationController?.pushViewController(firstLaunchVC, animated: true)
这是 bottom
的 pushing
但不是 fullscreen
。我也在终端中收到此消息:
Setting modalPresentationStyle once <UINavigationController: 0x1060f2a00> has been presented will have no effect until it is dismissed and presented again.
如何从 presented
ViewController
推送全屏?
我希望我说清楚了我的问题。如果您需要更多信息,请告诉我。
转换协调器 - UINavigationControllerDelegate
创建一个符合 UINavigationControllerDelegate
的简单 class,我不会详细说明,但作为您问题答案的主要方法是 navigationController(_:animationControllerFor:from:to:)
在此方法的主体中,您可以检索正在执行的操作(推送、弹出...),此外,您还可以根据视图控制器(从、到)为动画师做出决定。
如果你想要 默认 动画师只是 return nil.
例子
func navigationController(_ navigationController: UINavigationController, animationControllerFor operation: UINavigationControllerOperation, from fromVC: UIViewController, to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
switch operation {
case .push: // For push method
return YourCustomAnimator() //Conforming to `UIViewControllerAnimatedTransitioning`
case .pop:
return nil // For pop we want default animation
// I skipped the default case
}
// CASE 2
// Or for example you want to make custom animation only for specific view controller
if toVC is SpecialViewController {
return YourCustomAnimator()
}
return nil // for the rest use default animation
}
我通过调用这个修复了它:
let navigationController = UINavigationController(rootViewController: firstLaunchVC)
navigationController.modalPresentationStyle = .fullScreen
present(navigationController, animated: true)
这正是我想要的工作方式,尽管我不太确定我是否搞砸了我的 ViewController-Hirarchy
...无论如何它正在工作 :D 感谢您的帮助
在我的应用程序中,我有一个 MainVC
。从那里我 present
另一个 ViewControllerB
我想 push
在那里所以这就是我实现这个的方法:
let ViewControllerB = self.storyboard?.instantiateViewController(withIdentifier: "ViewControllerB") as! ViewControllerB
let navController = UINavigationController(rootViewController: communityVC)
self.present(navController, animated: true, completion: nil)
这正是我想要的效果。然而在
ViewControllerB
我还想 push
某个 ViewControllerC
全屏 来自 底部 而不仅仅是内部modalView
。我这样称呼:
let firstLaunchVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "FirstLaunchVC")
let transition:CATransition = CATransition()
transition.duration = 0.5
transition.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut)
transition.type = CATransitionType.push
transition.subtype = CATransitionSubtype.fromTop
self.navigationController?.modalPresentationStyle = .fullScreen
self.navigationController!.view.layer.add(transition, forKey: kCATransition)
self.navigationController?.pushViewController(firstLaunchVC, animated: true)
这是 bottom
的 pushing
但不是 fullscreen
。我也在终端中收到此消息:
Setting modalPresentationStyle once <UINavigationController: 0x1060f2a00> has been presented will have no effect until it is dismissed and presented again.
如何从 presented
ViewController
推送全屏?
我希望我说清楚了我的问题。如果您需要更多信息,请告诉我。
转换协调器 - UINavigationControllerDelegate
创建一个符合 UINavigationControllerDelegate
的简单 class,我不会详细说明,但作为您问题答案的主要方法是 navigationController(_:animationControllerFor:from:to:)
在此方法的主体中,您可以检索正在执行的操作(推送、弹出...),此外,您还可以根据视图控制器(从、到)为动画师做出决定。
如果你想要 默认 动画师只是 return nil.
例子
func navigationController(_ navigationController: UINavigationController, animationControllerFor operation: UINavigationControllerOperation, from fromVC: UIViewController, to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
switch operation {
case .push: // For push method
return YourCustomAnimator() //Conforming to `UIViewControllerAnimatedTransitioning`
case .pop:
return nil // For pop we want default animation
// I skipped the default case
}
// CASE 2
// Or for example you want to make custom animation only for specific view controller
if toVC is SpecialViewController {
return YourCustomAnimator()
}
return nil // for the rest use default animation
}
我通过调用这个修复了它:
let navigationController = UINavigationController(rootViewController: firstLaunchVC)
navigationController.modalPresentationStyle = .fullScreen
present(navigationController, animated: true)
这正是我想要的工作方式,尽管我不太确定我是否搞砸了我的 ViewController-Hirarchy
...无论如何它正在工作 :D 感谢您的帮助