zoukankan      html  css  js  c++  java
  • UISearchDisplayController animate Cancel button

    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上才可以。

  • 相关阅读:
    dropdownList级联刷新gridView
    Jquery解析json数据
    ASP.NET UserControl 通信
    sharepointWebPart开发、部署、发布过程全记录
    buffer和cache怎么让你们解释的那么难理解?
    Global.asax用法分析
    1、什么是ASP.NET MVC
    在Global.asax文件里实现通用防SQL注入漏洞程序
    ABP vNext V5 + VS2022+ .Net 6.0 学习笔记(1)
    使用IIS时的小问题
  • 原文地址:https://www.cnblogs.com/iosdev/p/2849683.html
Copyright © 2011-2022 走看看