代码之家  ›  专栏  ›  技术社区  ›  lascoff

iOS Swift导航通过重定向展开

  •  0
  • lascoff  · 技术社区  · 9 年前

    我想实现以下功能:(我正在使用导航控制器) enter image description here

    视图A有多个选项,用于确定要选择的路径。首先显示视图B,然后使用导航控制器显示视图C。工具栏的第一个项执行展开以查看a。该项有效。在工具栏中的第二项,我不仅要展开到A,而且要重定向到视图E。

    视图控制器中的代码如下所示:

    @IBAction func unwindToHomeController(segue: UIStoryboardSegue) {
        self.performSegue(withIdentifier: "toPerson", sender: self)
    }
    

    当我单击工具栏中的第二项时,视图E显示,但视图A在短暂延迟后立即显示。

    如何停止视图A的显示?

    也许有更好的方法。

    1 回复  |  直到 9 年前
        1
  •  1
  •   bubuxu    9 年前

    您需要等待动画完成后才能执行E:

    class ViewController: UIViewController {
    
        @IBAction func unwindToA(segue: UIStoryboardSegue) {
        }
    
        @IBAction func unwindToE(segue: UIStoryboardSegue) {
            CATransaction.begin()
            CATransaction.setCompletionBlock { 
                self.performSegue(withIdentifier: "E", sender: nil)
            }
            CATransaction.commit()
        }
    
    }
    

    Normal unwind

    更新 避免 闪烁 显示按下E的同时

    1) 取消展开功能:

    extension ViewController {
    
        @IBAction func unwindToA(segue: UIStoryboardSegue) {
        }
    
    //  @IBAction func unwindToE(segue: UIStoryboardSegue) {
    //      CATransaction.begin()
    //      CATransaction.setCompletionBlock { 
    //          self.performSegue(withIdentifier: "E", sender: nil)
    //      }
    //      CATransaction.commit()
    //  }
    
    }
    

    2) 创建自定义序列:

    class MyUnwindSegue: UIStoryboardSegue {
    
        override func perform() {
    
            guard let nav = source.navigationController else { return }
            guard let root = nav.viewControllers.first else { return }
            let viewControllers = [root, destination]
            nav.setViewControllers(viewControllers, animated: true)
    
        }
    
    }
    

    3) 将序列图像板中的segue更新为MyUnwindSegue(确保将模块选择为项目模块,而不是 空的 ):

    Using custom unwind segue

    推荐文章