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;
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容