ios 7 新增了頁面右滑的效果,是以UINavigationController為容器的ViewController間右滑切換頁面,代碼需要設置:
self.navigationController.interactivePopGestureRecognizer.enabled = YES;(default is YES)
可以看到蘋果給navigationController添加了一個手勢(具體為UIScreenEdgePanGestureRecognizer(邊緣手勢,同樣是ios7以后才有的)),就是利用這個手勢實現的 ios7的側滑返回。
有時候我們需要隱藏navigationBar,但是隱藏之后系統默認的滑動返回操作就沒有了。
一般解決方案都是:
self.navigationController.interactivePopGestureRecognizer.delegate = nil
但是很多時候會有各種問題,所以我們換一個思路去解決。
我們可以在需要隱藏navigationBar的controller里面的viewWillAppear添加
[self.navigationController.view sendSubviewToBack:self.navigationController.navigationBar];
然后在viewWillDisappear
[self.navigationController.view bringSubviewToFront:self.navigationController.navigationBar];
這樣既解決了隱藏navigationBar 也沒有失去滑動返回。