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. c# 通过文件夹共享复制文件到服务器

    public static string[] GetFileNames(string directoryPath, string searchName) { return Directory.GetF ...

  2. ThinkTemplate模板引擎的设计和使用方法

    在PHP开发的过程中,我们会接触到很多的模板引擎,包括FastTemplate.SmartTemplate.Smarty.tinybutstrong等,通常都是为了满足MVC开发模式的表现层需要,让显 ...

  3. 20155322 2016-2017-2 《Java程序设计》第8周学习总结

    20155322 2016-2017-2 <Java程序设计>第8周学习总结 教材学习内容总结 第八周学习的主要内容是课本的第十四第十五章,主要学习了以下知识点: 了解NIO 会使用Cha ...

  4. L3-011 直捣黄龙 (30 分)

    本题是一部战争大片 —— 你需要从己方大本营出发,一路攻城略地杀到敌方大本营.首先时间就是生命,所以你必须选择合适的路径,以最快的速度占领敌方大本营.当这样的路径不唯一时,要求选择可以沿途解放最多城镇 ...

  5. node.js + express 初体验【hello world】

    [node.js]  一个神奇的XX 呵呵 :) 不知道怎么形容他才好! [express] 是node.js 开发web应用程序的框架 开发环境:XP 大家共同进步吧 :) 一:前期准备: 1:下载 ...

  6. Linux wc指令解析

    wc指令比较实用,可以统计文件中的字节数.字符数.行数.字数等. 先通过 wc --help 查看指令帮助. $ wc --help Usage: wc [OPTION]... [FILE]... o ...

  7. WinForm 每用户只允许创建一个实例

    string mutexName = System.Environment.UserName + "nono"; bool runone; System.Threading.Mut ...

  8. vim自定义配置之自动括号

    BundlenInstall安装auto-pairs vimConfig/plugin/auto-pairs-setting.vim let g:autopairsflymode=

  9. 第九章 自定义mixer adapter

    1 install/kubernetes/helm/istio/templates/crds.yaml 序号 名称 用途 分类 归属 virtualservices.networking.istio. ...

  10. sort+函数指针、sort+比较器对象、qsort速度比较

    一.上代码 #include<bits/stdc++.h> using namespace std; #define MAXN 50000000 struct TS { int a, b, ...