在iOS7中,新增长了一个小小的功能,也就是这个api:
self
.
navigationController
.
interactivePopGestureRecognizer.enabled = YES;
这个api功能就是在NavigationController堆栈内的UIViewController能够支持右滑手势,也就是不用点击右上角的返回按钮,轻轻在屏幕左边一滑,屏幕就会返回,随着ios设备屏幕的增大,这个小功能让手指短,拇指大和手残人士看到了福音。
这个功能是好,可是常常咱们会有需求定制返回按钮,若是手动定制了返回按钮,这个功能将会失效,也就是自定义了navigationItem的leftBarButtonItem,那么这个手势就会失效。解决方法找到两种
1.从新设置手势的delegate
self.navigationController.interactivePopGestureRecognizer.delegate = (id)self;
|
2.固然你也能够本身响应这个手势的事件
[self.navigationController.interactivePopGestureRecognizer addTarget:self action:@selector(handleGesture:)];
|
若是想保留系统的边缘手势, 还想修改leftBarButtonItem
在基类的ViewController中 实现以下方法,可达到保留返回方法和箭头样式,并修改文字的目的
UIBarButtonItem *bar = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:nil action:nil];
self.navigationItem.backBarButtonItem = bar;
特别注意: 基类