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

  • 相关阅读:
    day7随笔
    day6随笔
    day5笔记
    uniapp 全屏蒙版下的其他view禁止滑动
    uniapp scroll-view 组件右侧的滚动条
    uni 组件 头部
    根据两点的经纬度查询两点间的距离
    仅供学习使用的一些 相关vue类
    仅供学习使用的一些样式+行为
    百度地图简单调用
  • 原文地址:https://www.cnblogs.com/iosdev/p/2849683.html
Copyright © 2011-2022 走看看