博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
UISearchDisplayController animate Cancel button
阅读量:7231 次
发布时间:2019-06-29

本文共 1601 字,大约阅读时间需要 5 分钟。

FUCK, SHIT, etc. 一系列脏话,日了等。为啥,因为烦的要命。主要是碰到了一个问题,我要在UIsearchBar的左边加一个按钮,这样UISearchBar的width就变小窄了。但是每次点击Cancel的时候,UISearBar又填充了整个视图的宽度。如下图:

 

解决方法:

-(void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController*)controller{
// animate the search bar to the left ie. x=0[UIView animateWithDuration:0.25f animations:^{
     CGRect frame = controller.searchBar.frame; frame.origin.x =0; controller.searchBar.frame = frame;} ]; // remove all toolbar items[self.toolbar setItems:nil animated:YES];}
-(void)searchDisplayControllerDidEndSearch:(UISearchDisplayController*)controller{// animate search bar back to its previous position and size// in my case it was x=55, y=1// and reduce its width by the amount moved, again 55px[UIView animateWithDuration:0.25f                           delay:0.0f// the UIViewAnimationOptionLayoutSubviews is IMPORTANT,// otherwise you get no animation// but some kind of snap-back movement                         options:UIViewAnimationOptionLayoutSubviews                      animations:^{CGRect frame =self.toolbar.frame;                         frame.origin.y =1;                         frame.origin.x =55;                         frame.size.width -=55;                         controller.searchBar.frame = frame;}                      completion:^(BOOL finished){// when finished, insert any tool bar items you had[self.toolbar setItems:[NSArray arrayWithObject:self.currentLocationButton] animated:YES];}];}

 如下效果:

 

 

 PS:

self.searchDisplayController.searchBar.frame=CGRectMake(10, 144, 152, 44); 这样不会改变SearchBar的宽度,需要将searchbar放在一个view上才可以。

 

转载地址:http://capfm.baihongyu.com/

你可能感兴趣的文章
南昌互联网行业协会筹办者祝真和华罡团队-2014年12月江西IDC排行榜
查看>>
二叉树搜索
查看>>
redis的有序集合ZSET(stored set)
查看>>
C++获取时间的方法
查看>>
Android隐藏输入法键盘(hideSoftInputFromInputMethod没有效果)
查看>>
Linux USB驱动数据结构
查看>>
PKI(公钥基础设施)基础知识笔记
查看>>
tiny4412 裸机程序 一、说明【转】
查看>>
CSS自己主动换行、强制不换行、强制断行、超出显示省略号
查看>>
18-hadoop-weather案例
查看>>
Vue模板内容
查看>>
[Phonegap+Sencha Touch] 移动开发24 打包wp8.1的App,执行时输入框聚焦弹出软键盘之后,界面上移而不恢复原位的解决的方法...
查看>>
解决duilib水平布局(HorizontalLayout)中控件位置计算错误的问题
查看>>
Spring4.2 集成ActiveMQ5.14
查看>>
SSL/TLS协议运行机制的概述_转
查看>>
数据库可视化操纵软件有navicat和sqlyog
查看>>
【转】批处理命令请求以管理员身份运行
查看>>
ASP.NET Web API 过滤器创建、执行过程(二)
查看>>
python读取excel(xlrd)
查看>>
RSA的公钥、私钥
查看>>