iOS开发-通过Navigation Controller实现视图切换

230 阅读1分钟

Navigation Controller是一个视图控制器栈,在storyboard中,可以将其与View Controller连接,再将该View Controller连向其他View Controller。

取消勾选Navigation Item。

弹栈方法:

1、点击UIButton。

@IBAction func press(_ sender: UIButton) {

        self.navigationController?.popViewController(animated: true)

    }

2、通过代理,实现右滑返回。

在视图控制器中选择代理UIGestureRecognizerDelegate; 在viewDidLoad中添加:

    self.navigationController?.interactivePopGestureRecognizer?.isEnabled = true
    self.navigationController?.interactivePopGestureRecognizer?.delegate = self