iOS修改导航栏返回按钮点击区域

 1.系统导航栏返回按钮点击响应区域,默认是很大,大概100px左右,滚动时容易触摸到返回按钮。
 2.根据Reveal其实无法查看返回按钮点击区域具体是UINavigationItemView上的哪个控件,所以无法直接修改点击响应区域,只能加一层先屏蔽系统的响应区域,再执行自定义的点击事件。


- (void)loadView{
    [super loadView];

    self.title = @"第二界面";
    self.view.backgroundColor = [UIColor whiteColor];

    UIButton *but = [UIButton buttonWithType:UIButtonTypeCustom];
    [but setImage:[UIImage imageNamed:@"button_back_nor"] forState:UIControlStateNormal];
    but.frame = CGRectMake(0, 0, 44, 44);
    but.backgroundColor = [UIColor redColor];
    [but addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];

  //方案一(该视图没有点击事件都可以,frame不小于but就可以屏蔽系统的点击区域)
  //  UIView *btnView = [[UIView alloc] initWithFrame:but.bounds];
  //  [btnView addSubview:but];

  //方案二,此方法可以添加到分类中
  UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:but];
  UIBarButtonItem *spaceItem = [[UIBarButtonItem alloc]initWithCustomView:[UIButton buttonWithType:UIButtonTypeCustom]];
  self.navigationItem.leftBarButtonItems =  [NSArray arrayWithObjects:item,spaceItem,nil];;

  UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:but];
  self.navigationItem.leftBarButtonItem = leftItem;
}

你可能感兴趣的:(iOS修改导航栏返回按钮点击区域)