UIViewController一般有點擊UINavigationController左上角返回按鈕關(guān)閉和向右滑動關(guān)閉兩種方式.
但若定義了UINavigationController的leftBarButtonItem后,UIVIewController是無法再滑動返回的.
不過,如果加上下面這句,便可以自定義LeftBarButtonItem后,仍然可以實現(xiàn)滑動關(guān)閉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;