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. New Concept English Two 17 43

    $课文41  你把那个叫帽子吗? 422. 'Do you call that a hat?' I said to my wife. “你把那个叫帽子吗?”我对妻子说. 423. 'You needn ...

  2. pycharm 设置py文件的默认模版头部信息

    pycharm 设置py文件的默认模版头部信息,打开设置settings 进入File->settings->Editor->File and Code Templates-> ...

  3. 转:Android-apt

    转自http://blog.csdn.net/zjbpku/article/details/22976291 What is this? The Android-apt plugin assists ...

  4. Leetcode 1022. Sum of Root To Leaf Binary Numbers

    dfs class Solution: def sumRootToLeaf(self, root: TreeNode) -> int: stack=[(root,0)] ans=[] bi_st ...

  5. 链表的实现、输出和反向 python

    链表节点包含两个元素:节点的值和指向的下一个节点,因此可以定义链表的类为: class linknode: def __init__(self,value=None,next=None): self. ...

  6. 关于CCRANDOM_0_1

    CCRANDOM_0_1的范围是[0,1)包括0但不包括1 CCRANDOM_0_1() * 1400.0f / 100.0f是0-13 另外每次随机都是相同的数,要随机下种子 srand((unsi ...

  7. FastAdmin 的 captcha 是如何来的?

    FastAdmin 的 captcha 是如何来的? 如何打开 FastAdmin 的验证吗? 文件位置 C:\www\fastadmin\application\config.php 改 login ...

  8. 【转】把VS的智能提示快捷键改成Eclipse的习惯

    原文网址:http://programmer.blog.51cto.com/2859493/1095529 平常我一会用eclipse开发,一会又操作VS,他们直接的智能提示快捷键不一样,弄的我老是敲 ...

  9. js setInterval每隔一段时间执行一次

    js setInterval每隔一段时间执行一次setInterval() 方法可按照指定的周期(以毫秒计)来调用函数或计算表达式.setInterval() 方法会不停地调用函数,直到 clearI ...

  10. window.onload()和$(document).ready()区别

    执行时间:window.onload:必须等待网页中所有的内容加载完毕后(包括图片)才能执行;$(document).ready();网页中所有DOM结构绘制完毕后就执行,可能DOM元素关联的东西并没 ...