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

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

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

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

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

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

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

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

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

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

- (void)searchDisplayController:(UISearchDisplayController *)controller didShowSearchResultsTableView:(UITableView *)tableView  {
tableView.frame =CGRectMake(, , 320, 480--);
}

7、多次测试后发现,每次第一次执行无效,原因是由于searchDisplayControllerWillBeginSearch第一次执行时searchResultsTableView.superview为null,没有添加到父视图,可以使用两种方案解决

方案一,延时执行:

- (void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller
{
NSLog(@"%@,%@",self.searchDisplayController.searchResultsTableView,self.searchDisplayController.searchResultsTableView.superview); [self performSelector:@selector(resetFrame) withObject:nil afterDelay:0.1]; } - (void)resetFrame
{
CGRect bounds = self.searchDisplayController.searchResultsTableView.superview.bounds;
CGFloat offset = CGRectGetMinY(bounds);
if (offset == )
{
self.searchDisplayController.searchResultsTableView.superview.bounds =CGRectMake(,,,);
} for(UIView * v in self.searchDisplayController.searchResultsTableView.superview.subviews)
{
NSLog(@"%@",[v class]);
if([v isKindOfClass:NSClassFromString(@"_UISearchDisplayControllerDimmingView")])
{
v.frame = CGRectMake(,,,); //
}
}
}

方案二,注册键盘通知:

- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(resetFrame)
name:UIKeyboardWillShowNotification object:nil];
}
- (void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated]; [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
} - (void)resetFrame
{
CGRect bounds = self.searchDisplayController.searchResultsTableView.superview.bounds;
CGFloat offset = CGRectGetMinY(bounds);
if (offset == )
{
self.searchDisplayController.searchResultsTableView.superview.bounds =CGRectMake(,,,);
} for(UIView * v in self.searchDisplayController.searchResultsTableView.superview.subviews)
{
NSLog(@"%@",[v class]);
if([v isKindOfClass:NSClassFromString(@"_UISearchDisplayControllerDimmingView")])
{
v.frame = CGRectMake(,,,); //
}
}
}

问题解决!

注:以上frame调整在ios7执行,ios7之前版本不需要,具体调整的frame大小可以根据自己的需求修改。

UISearchDisplayController 阴影遮盖frame调整的更多相关文章

  1. iOS 热点、通话时候TabView的Frame调整

    - (void)application:(UIApplication *)application didChangeStatusBarFrame:(CGRect)oldStatusBarFrame{ ...

  2. VC++界面编程之--阴影窗口的实现详解

    转载:http://blog.csdn.net/rmxming/article/details/11661365 对于我们这些控件狂来说,窗口阴影也是一个必不可少的实现需求.虽说其没多大用,但对于增加 ...

  3. UIView阴影和圆角的关系

    UIView阴影和圆角的关系   UIView 的 clipsToBounds属性和CALayer的setMasksToBounds属性表达的意思是一致的. 取值:BOOL(YES/NO) 作用:决定 ...

  4. CSS3 盒阴影(box-shadow)详解

    CSS3 的 box-shadow 有点类似于 text-shadow,只不过不同的是 text-shadow 是对象的文本设置阴影,而 box-shadow 是给对象实现图层阴影效果.本文我们搁下I ...

  5. iOS Autolayout情况下,ViewController嵌套时,childViewController的Frame异常问题

    近期项目中,使用Storyboard.AutoLayout开发,某个ViewController中嵌套了多个子ViewController,结果在将其加入到父ViewController时,出现坐标异 ...

  6. 剖析QMenu & Qt完全定制化菜单

    贴张效果图:  定制包括: 1. 周边阴影 2. 菜单项的元素(分割符, 控制ICON大小, 文字显示位置与颜色, 子菜单指示符) 菜单内的效果, 部分可以使用stylesheet实现, 但要做到这样 ...

  7. Edge Animate初篇教程(二)

    Edge Animate 是Adobe最新出品的制作HTML5动画的可视化工具,简单的可以理解为HTML5版本的Flash Pro.在之后的文章中,我会逐一的介绍这款新的HTML5动画神器. 一.创建 ...

  8. 剖析虚幻渲染体系(15)- XR专题

    目录 15.1 本篇概述 15.1.1 本篇内容 15.1.2 XR概念 15.1.2.1 VR 15.1.2.2 AR 15.1.2.3 MR 15.1.2.4 XR 15.1.3 XR综述 15. ...

  9. iOS之UIKit系列教程<一>

    前言:博主接触iOS的编程也有一段时间,今天把有关UI控件的一些知识在这里做一些总结. 申明:此系列文章都是使用目前最新版本swift3.0.1进行讲解的,与其他版本可能略有差异. 一,UIKit之设 ...

随机推荐

  1. Memcached介绍及相关知识

    memcached简介 1.memcached是一个免费开源的.高性能的,具有分布式内存对象的缓存系统.memcached通过在内存里维护一个统一的巨大的hash表,它能够用来存储各种格式的数据,包括 ...

  2. 判断一棵树是否为二叉搜索树(二叉排序树) python

    输入一棵树,判断这棵树是否为二叉搜索树.首先要知道什么是排序二叉树,二叉排序树是这样定义的,二叉排序树或者是一棵空树,或者是具有下列性质的二叉树: (1)若左子树不空,则左子树上所有结点的值均小于它的 ...

  3. springboot整合mybatis增删改查(二):springboot热部署

    SpringBoot整合热部署 传统情况下, 我们用idea运行springboot程序时, 如果我们需要修改类里的方法,或者其他信息 我们需要修改完保存,并且重启springboot,有时候会很浪费 ...

  4. hdu 3613 Best Reward

    After an uphill battle, General Li won a great victory. Now the head of state decide to reward him w ...

  5. streamsets 错误记录处理

    我们可以在stage 级别,或者piepline 级别进行error 处理配置 pipeline的错误记录处理 discard(丢踢) send response to Origin pipeline ...

  6. QLoo graphql engine了解

    参考架构图 处理流程 使用gloo注册服务api 发现断电以及serverless 函数 更新graphql schema 在qloo的resolvermap 中连接schema定义的字段 特性 不用 ...

  7. linux环境下git的安装配置

    1.查看git的最新版本: 查看最新版git:访问https://www.kernel.org/pub/software/scm/git/或者https://github.com/git/git/re ...

  8. 定时器Timer&ScheduledThreadPoolExecutor

    定时器Timer&ScheduledThreadPoolExecutor /** * @ClassName: TimerTest * @author: daniel.zhao * @date: ...

  9. vmware player 在windows下nat模式中的端口映射

    1.设置虚拟机nat共享的网卡为固定ip vmware虚拟机使用nat网络时,是VMware Network Adapter VMnet8网卡提供的nat服务.查看VMware Network Ada ...

  10. JS代码压缩格式化在线地址

    JS在线格式化: http://tool.oschina.net/codeformat/js JS在线压缩: http://dean.edwards.name/packer/