iOS 7 新增了頁(yè)面右滑的效果,是以UINavigationController為容器的ViewController間右滑切換頁(yè)面
self.navigationController.interactivePopGestureRecognizer.enabled = YES;(default is YES)
可以看到蘋果給navigationController添加了一個(gè)手勢(shì)(具體為UIScreenEdgePanGestureRecognizer(邊緣手勢(shì),同樣是ios7以后才有的)),就是利用這個(gè)手勢(shì)實(shí)現(xiàn)的 ios7的側(cè)滑返回。
有時(shí)候我們需要隱藏navigationBar,但是隱藏之后系統(tǒng)默認(rèn)的滑動(dòng)返回操作就沒有了。
一般解決方案都是:
self.navigationController.interactivePopGestureRecognizer.delegate
但是很多時(shí)候會(huì)有各種問題,所以我們換一個(gè)思路去解決。
我們可以在需要隱藏navigationBar的controller里面的viewWillAppear添加
[self.navigationController.view sendSubviewToBack:self.navigationController.navigationBar];
然后在viewWillDisappear
[self.navigationController.view bringSubviewToFront:self.navigationController.navigationBar];
這樣既解決了隱藏navigationBar 也沒有失去滑動(dòng)返回。
代碼需要設(shè)置:
@implementation LePhoneViewController
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.navigationController.view sendSubviewToBack:self.navigationController.navigationBar];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear: animated];
[self.navigationController.view bringSubviewToFront:self.navigationController.navigationBar];
}
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor colorWithHexString:@"EFEFEF"];
self.navigationController.navigationBar.hidden = YES;
}