UIViewController一般有点击UINavigationController左上角返回按钮关闭和向右滑动关闭两种方式.
但若定义了UINavigationController的leftBarButtonItem后,UIVIewController是无法再滑动返回的.
不过,如果加上下面这句,便可以自定义LeftBarButtonItem后,仍然可以实现滑动关闭ViewController的功能:
self.navigationController.interactivePopGestureRecognizer.delegate=nil;
以下是一个完整的例子:
UIButton* button = [[UIButtonalloc]initWithFrame:CGRectMake(0,0,60,60)];
[buttonsetImage:[UIImageimageNamed:@"btn_back_white"]forState:UIControlStateNormal];
[buttonaddTarget:selfaction:@selector(onBackClick)forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem* backButton = [[UIBarButtonItemalloc]initWithCustomView:button];
self.navigationItem.leftBarButtonItem= backButton;
self.navigationController.interactivePopGestureRecognizer.delegate=nil;