导航栏滑动手势
2016-10-31 本文已影响47人
辛小二
重新绘制导航栏返回按钮 代码如下:
替换返回按钮非常简单,只需要在ViewController中创建一个UIBarButtonItem和一张图片,并为按钮添加相应的点击事件即可--
- (void)viewDidLoad {[super viewDidLoad];
Do any additional setup after loading the view.
UIButton * leftBtn = [UIButton buttonWithType:UIButtonTypeSystem];
leftBtn.frame = CGRectMake(0, 0, 25,25);
[leftBtn setBackgroundImage:[UIImage imageNamed:@"nav_back"] forState:UIControlStateNormal];
[leftBtn addTarget:self action:@selector(leftBarBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:leftBtn];
}
- (void)leftBarBtnClicked:(UIButton *)btn
{
[self.navigationController popViewControllerAnimated:YES];
}
手势生效
如果自定义导航栏按钮会使滑动手势失效。只要重新添加导航栏的interactivePopGestureRecognizer的delegate手势即可回归。
self.navigationController.interactivePopGestureRecognizer.delegate = self;
本人个人微信公众号地址(喜欢记得关注😯)
辛小二个人微信公众号地址