UISearchDisplayController 阴影遮盖frame调整
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调整的更多相关文章
- iOS 热点、通话时候TabView的Frame调整
- (void)application:(UIApplication *)application didChangeStatusBarFrame:(CGRect)oldStatusBarFrame{ ...
- VC++界面编程之--阴影窗口的实现详解
转载:http://blog.csdn.net/rmxming/article/details/11661365 对于我们这些控件狂来说,窗口阴影也是一个必不可少的实现需求.虽说其没多大用,但对于增加 ...
- UIView阴影和圆角的关系
UIView阴影和圆角的关系 UIView 的 clipsToBounds属性和CALayer的setMasksToBounds属性表达的意思是一致的. 取值:BOOL(YES/NO) 作用:决定 ...
- CSS3 盒阴影(box-shadow)详解
CSS3 的 box-shadow 有点类似于 text-shadow,只不过不同的是 text-shadow 是对象的文本设置阴影,而 box-shadow 是给对象实现图层阴影效果.本文我们搁下I ...
- iOS Autolayout情况下,ViewController嵌套时,childViewController的Frame异常问题
近期项目中,使用Storyboard.AutoLayout开发,某个ViewController中嵌套了多个子ViewController,结果在将其加入到父ViewController时,出现坐标异 ...
- 剖析QMenu & Qt完全定制化菜单
贴张效果图: 定制包括: 1. 周边阴影 2. 菜单项的元素(分割符, 控制ICON大小, 文字显示位置与颜色, 子菜单指示符) 菜单内的效果, 部分可以使用stylesheet实现, 但要做到这样 ...
- Edge Animate初篇教程(二)
Edge Animate 是Adobe最新出品的制作HTML5动画的可视化工具,简单的可以理解为HTML5版本的Flash Pro.在之后的文章中,我会逐一的介绍这款新的HTML5动画神器. 一.创建 ...
- 剖析虚幻渲染体系(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. ...
- iOS之UIKit系列教程<一>
前言:博主接触iOS的编程也有一段时间,今天把有关UI控件的一些知识在这里做一些总结. 申明:此系列文章都是使用目前最新版本swift3.0.1进行讲解的,与其他版本可能略有差异. 一,UIKit之设 ...
随机推荐
- erhai系统使用_web
使用前说明1.安装mysql数据库,安装数据库管理器EMS(SQL Manager Lite for MySQL),将数据库导入数据库管理器: 注意对配置文件my.ini的修改.2.启动resin W ...
- Linux 网络编程->epoll<-LT/ET模式整理(~相逢何必曾相识~)
今天自己整理一下epoll,网上有很多经典的介绍,看了很多~收藏了很多~还是整理一下做个积累, 自己的东西好找~ 1. epoll 模型简介 epoll 是Linux I/O 多路复用接口 selec ...
- 初始化一个static的Map变量
第一种方法:static块初始化 public class Demo{ private static final Map<String, String> myMap; static { m ...
- VirtualBox只能生成32位虚拟机
/************************************************************************* * VirtualBox只能生成32位虚拟机 * ...
- vi/vim使用进阶: 在VIM中使用GDB调试 – 使用vimgdb
vi/vim使用进阶: 在VIM中使用GDB调试 – 使用vimgdb << 返回vim使用进阶: 目录 本节所用命令的帮助入口: :help vimgdb 在UNIX系统最初设计时,有一 ...
- jdbc-DAO的实现
什么是 DAO DAO(Data Access Object)是一个数据访问接口,夹在业务逻辑与数据库资源中间. 在核心J2EE模式中是这样介绍DAO模式的:为了建立一个健壮的J2EE应用,应该将所有 ...
- vue.js权威指南----代码解释实例
1:P61(值绑定) <input type="checkbox" v-model="toggle" :true-value="a" ...
- Linux内核调试
1.控制台优先级配置cat /proc/sys/kernel/printk6 4 1 76是控制台的优先级,打印信息的优先级要比它高才能打印出.4是默认的优先级cat /var/log/message ...
- Ngnix常用的操作
Nginx的常用参数如下: # /usr/local/nginx/sbin/nginx -h nginx version: nginx/0.7.63 Usage: nginx [-?hvVt] [-s ...
- Keras 入门
“sample”“batch”“epoch” Sample:样本,比如:一张图像是一个样本,一段音频也是一个样本. Batch:批,含有N个样本的集合.每一个batch的样本都是独立的并行处理.在训练 ...