【问题标题】:More than one navigation item view iOS多个导航项视图 iOS
【发布时间】:2015-10-17 20:49:19
【问题描述】:

我试图将搜索栏和分段控件放入导航栏中。目前这是我的代码,它可以工作,但只能添加其中一个。

self.navigationItem.titleView = searchController.searchBar; self.navigationItem.titleView = segmentedControl1;

【问题讨论】:

  • 为此使用范围栏

标签: ios uinavigationcontroller uisegmentedcontrol uisearchcontroller


【解决方案1】:

因为您要替换 1st view 2nd view。

试试下面的代码

CGRect titleViewFrame = self.navigationController.navigationBar.frame;

CGRect searchBarFrame = titleViewFrame;
searchBarFrame.size.width = titleViewFrame.size.width/2;//say, the search bar width = 0.5*search_bar_width

CGRect segmentFrame = titleViewFrame;
segmentFrame.origin.x = searchBarFrame.size.width;
segmentFrame.size.width = searchBarFrame.size.width;

UIView *titleView = [[UIView alloc]initWithFrame:titleViewFrame];
searchController.searchBar.frame = searchBarFrame;//set here changed search bar frame
[titleView addSubview:searchController.searchBar];


UIView *segmentView = [[UIView alloc]initWithFrame:segmentFrame];
segmentView.backgroundColor =[UIColor redColor];

[titleView addSubview:segmentView];

self.navigationItem.titleView = titleView; 

【讨论】:

  • 我无法按导航栏大小以外的任何内容
  • 你的意思是 UISegmentedContol 不会触发事件?
  • 不,我已经完成了所有设置;搜索栏应该在导航栏上,分段控件在它下面,但是当我按下分段控件时,它甚至没有注意到它正在被点击,它只是点击它下面的内容.我认为这是因为它不在导航栏上,所以我认为我需要使导航栏更长一点。你知道怎么做吗?
  • 给我截图
  • 你不应该改变导航栏的默认高度。但如果你这样做,我会在苹果审查时间更改拒绝
【解决方案2】:

您需要关闭导航栏! 并将导航栏自定义为视图!

[self.navigationController setNavigationBarHidden:YES animated:YES];

使用 UIView 为该导航控制器自定义视图。

【讨论】:

  • 能否详细说明一下?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-07-28
  • 1970-01-01
  • 1970-01-01
  • 2017-01-09
相关资源
最近更新 更多