iOS开发-UI控件:关于使用UISearchDisplayController

iOS7中UISearchDisplayController 与UISearchBar结合使用时,有时候会出现搜索框获得焦点时,阴影遮盖部分挡住了搜索框,影响用户使用,如下图

bubuko.com,布布扣

 

API中没有阴影图层的接口,尝试分析解决

1、使用Reveal,查找遮盖图层,发现为_UISearchDisplayControllerDimmingView

bubuko.com,布布扣

2、找到该图层,修改对应的frame,通过上图可以发现dimmingview与searchResultsTableView为同一视图的子图层。

?
1
- ( void )searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller<br>{ 
?
1
2
3
4
5
6
7
8
for (UIView * v in controller.searchResultsTableView.superview.subviews)
  {
      NSLog (@ "%@" ,[v  class ]);
      if ([v isKindOfClass: NSClassFromString (@ "_UISearchDisplayControllerDimmingView" )])
      {
          v.frame = CGRectMake(0,20,320,400);  //
      }
  }
?
1
<br>}  <br>  

 3、通过以上代码修改,遮罩图层没有在挡住搜索框了,但操作搜索框,还是发现搜索框的下区域不能获取焦点,Cancel按钮不方便使用。

bubuko.com,布布扣

4、通过上个图可以看到虽然遮罩层下去了,但还是有个图层在挡住,左边列表该图层显示为searchResultsTableView的父视图,再次修改代码。

bubuko.com,布布扣
- (void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller
{
    
    controller.searchResultsTableView.superview.bounds = CGRectMake(0,22,320,400);
    for(UIView * v in controller.searchResultsTableView.superview.subviews)
    {
        NSLog(@"%@",[v class]);
        if([v isKindOfClass:NSClassFromString(@"_UISearchDisplayControllerDimmingView")])
        {
            v.frame = CGRectMake(0,20,320,400); //
        }
    }
}
bubuko.com,布布扣

 5、搜索框可以正常使用。

bubuko.com,布布扣

6、同样,如果需要调整searchResultsTableView的frame,在追加下面的代码

bubuko.com,布布扣
- (void)searchDisplayController:(UISearchDisplayController *)controller didShowSearchResultsTableView:(UITableView *)tableView  {
    tableView.frame =CGRectMake(0, 20, 320, 480-64-44);
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值