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之设 ...
随机推荐
- 汉诺塔(Hanoi)——小小算法
传送门: 袁咩咩的小小博客 汉诺(Hanoi)塔源于古印度,是非常著名的智力趣题,大意如下: 勃拉玛是古印度的一个开天辟地的神,其在一个庙宇中留下了三根金刚石的棒,第一 根上面套着64个大小不一的圆形 ...
- [CF995F]Cowmpany Cowmpensation
codeforces description 一棵\(n\)个节点的树,给每个节点标一个\([1,m]\)之间的编号,要求儿子的权值不大于父亲权值.求方案数.\(n\le3000,n\le10^9\) ...
- Java编程之Date的相关操作
一:讲字符串的时间格式数据转换成时间对象 //将字符串的时间数据,转换成时间 String dateString="2007-12-12"; DateFormat date=new ...
- form表单序列化serialize-object.js
<form class="form-horizontal" role="form" id="myform" action=" ...
- 刷新SQL Server所有视图、函数、存储过程 更多 sql 此脚本用于在删除或添加字段时刷新相关视图,并检查视图、函数、存储过程有效性。 [SQL]代码 --视图、存储过程、函数名称 DECLARE @NAME NVARCHAR(255); --局部游标 DECLARE @CUR CURSOR --自动修改未上状态为旷课 SET @CUR=CURSOR SCROLL DYNAMIC FO
刷新SQL Server所有视图.函数.存储过程 更多 sql 此脚本用于在删除或添加字段时刷新相关视图,并检查视图.函数.存储过程有效性. [SQL]代码 --视图.存储过程.函数名称 DE ...
- PDB文件:每个开发人员都必须知道的 PDB Files
PDB文件:每个开发人员都必须知道的 PDB Files: What Every Developer Must Knowhttp://www.wintellect.com/CS/blogs/jro ...
- WCF 快速入门
定义服务契约 构建HelloWCF应用的第一步是创建服务契约.契约式是表示消息应用外形的主要方式.对于外形,是指服务暴露的操作,使用的消息 schema和每个操作实现的消息交换模式(MEP).总之,契 ...
- C BIN加密
#include <stdio.h> #include <string.h> #include <stdlib.h> #ifndef DWORD #define D ...
- C#操作 iis启用父目录
iis6实现: DirectoryEntry site = (DirectoryEntry)root.Invoke("Create", "IIsWebServer&quo ...
- 四.jQuery源码解析之jQuery.fn.init()的参数解析
从return new jQuery.fn.init( selector, context, rootjQuery )中可以看出 参数selector和context是来自我们在调用jQuery方法时 ...