【问题标题】:Push ViewController full screen from bottom inside ModalView在 ModalView 内从底部推送 ViewController 全屏
【发布时间】:2021-01-18 10:18:18
【问题描述】:

在我的应用程序中,我有一个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)

这是来自bottompushing,但不是fullscreen。我也在终端收到这条消息:

被呈现后设置 modalPresentationStyle 将无效,直到它被解除并再次呈现。

如何从presented ViewController 推送全屏?

我希望我把我的问题说清楚了。如果您需要有关某事的更多信息,请告诉我。

【问题讨论】:

    标签: ios swift uiviewcontroller uinavigationcontroller pushviewcontroller


    【解决方案1】:

    过渡协调器 - UINavigationControllerDelegate

    创建一个符合UINavigationControllerDelegate 的简单类,我不会详细说明,但作为您问题答案的主要方法是navigationController(_:animationControllerFor:from:to:)

    在该方法的主体内,您可以检索正在执行的操作(推送、弹出...),此外,您可以根据视图控制器(从、到)为动画师做出决定。

    如果你想要 default 动画师,只需返回 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
    }
    

    【讨论】:

    • 感谢您的回答。但我改变了问题。我一开始没有把问题说清楚。我希望是现在
    【解决方案2】:

    我通过调用这个来修复它:

    let navigationController = UINavigationController(rootViewController: firstLaunchVC)
    navigationController.modalPresentationStyle = .fullScreen
    present(navigationController, animated: true)
    

    这正是我希望它工作的方式,即使我不太确定我是否搞砸了我的 ViewController-Hirarchy... 无论如何它正在工作 :D 感谢您的帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-03-01
      • 2011-10-05
      • 1970-01-01
      • 2016-07-04
      • 1970-01-01
      • 2020-07-19
      • 2018-10-11
      • 2015-08-22
      相关资源
      最近更新 更多