Swift自定义UINavigationController添加右划返回

2016年02月16日星期二

好久都没有写东西了,连hexo的很多命令都不会用了,所以说,知识会随着时间的流逝而被人的大脑遗忘,只要不是经常重温一遍,再深刻的记忆也会被时间腐蚀掉。

今天,写个简单的东西,自定义UINavigationController,添加右划返回。系统自带的UINavigationController,自带右划返回,自定义的UINavigationController想要和系统一样该怎么实现喃?很简单。

1
2
3
4
5
6
7
8
9
10
11
12
13

class YourNavigationController: UINavigationController,UIGestureRecognizerDelegate {

override func viewDidLoad() {
super.viewDidLoad()
//设置右划手势的代理为自己
self.interactivePopGestureRecognizer?.delegate = self
}
override func pushViewController(viewController: UIViewController, animated: Bool) {
//设置右划返回为true
self.interactivePopGestureRecognizer?.enabled = true
}
}

就只需要 上面两行代码,就可以和系统一样,进行右划返回。

评论