【问题标题】:Segue From Right To Left Without Push Or Presenting ViewController从右到左 Segue,无需推送或呈现 ViewController
【发布时间】:2020-01-16 11:48:03
【问题描述】:

如果没有push or Persenting ViewController,是否有可能从Right To Left 执行segue。以下代码与动画效果很好,但如果我使用这个类,我的 TabBar 将被隐藏。如果我删除 Perform() TabBar 中的代码,则显示但动画停止 使用MDCBottomNavigationBar

class SegueFromRight: UIStoryboardSegue {
    override func perform() {
        let src = self.source
        let dst = self.destination
        src.view.superview?.insertSubview(dst.view, aboveSubview: src.view)

        dst.view.transform = CGAffineTransform(translationX: src.view.frame.size.width, y: 0)

        UIView.animate(withDuration: 0.25,delay: 0.0,options: UIView.AnimationOptions.curveEaseInOut,animations: {
            dst.view.transform = CGAffineTransform(translationX: 0, y: 0)
        },completion: { finished in
            src.navigationController?.pushViewController(dst, animated: false)
        }
        )
    }
}

有没有其他方法可以在不隐藏TabBar的情况下使用动画执行segue?

【问题讨论】:

    标签: swift xcode navigation segue uistoryboardsegue


    【解决方案1】:

    试试这个

    private func setupAlwaysVisibleView() {
            guard let tabBarController = self.tabBarController else { return }
    
            tabBarController.view.insertSubview(alwaysVisibleView, belowSubview: tabBarController.tabBar)
        }
    

    【讨论】:

    • 我正在使用MDCBottomNavigationBar
    • 在该导航栏中插入子视图...不在视图超级视图中
    【解决方案2】:

    我终于找到了答案。只是删除线Push ViewController

    class SegueFromRight: UIStoryboardSegue {
        override func perform() {
            let src = self.source
            let dst = self.destination
            src.view.superview?.insertSubview(dst.view, aboveSubview: src.view)
    
            dst.view.transform = CGAffineTransform(translationX: src.view.frame.size.width, y: 0)
    
            UIView.animate(withDuration: 0.25,delay: 0.0,options: UIView.AnimationOptions.curveEaseInOut,animations: {
                dst.view.transform = CGAffineTransform(translationX: 0, y: 0)
            },completion: { finished in
                //Remove Following line if you want to segue modally  
                //src.navigationController?.pushViewController(dst, animated: false)
            }
            )
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2011-01-25
      • 1970-01-01
      • 2020-07-10
      • 1970-01-01
      • 2015-04-04
      • 1970-01-01
      • 1970-01-01
      • 2013-04-07
      • 1970-01-01
      相关资源
      最近更新 更多