美文网首页
UISearchController好用,但是要避过这些坑

UISearchController好用,但是要避过这些坑

作者: 諾城 | 来源:发表于2018-07-18 11:15 被阅读0次

    1.搜索时searchBar向上偏移64

    设置definesPresentationContext为YES,可以保证在UISearchController在激活状态下用户push到下一个view controller之后search bar不会仍留在界面上。

    a、如果不添加上面这行代码,在设置hidesNavigationBarDuringPresentation这个属性为YES的时候,搜索框进入编辑模式会导致,searchbar向上偏移了64;

    b、如果添加了上面这行代码,在设置hidesNavigationBarDuringPresentation这个属性为YES的时候,输入框进入编辑模式正常显示和使用;

    2.搜索返回时searchBar向下偏移64

    a、在definesPresentationContext为YES和hidesNavigationBarDuringPresentation都设置为YES的时候,打开下一个页面,再返回,searchbar向下偏移64,这种情况可能有的人不会遇到,有的人会遇到,具体来说就是ios11之后的人不会遇到

    解决方法:navigationBar的translucent属性

    if(@available(iOS11.0, *)) {

            self.navigationController.navigationBar.translucent = NO;

        }else{

            self.navigationController.navigationBar.translucent = YES;

        }

    3.用UISearchController做的搜索框  ,更换背景颜色后 ,上下有两条黑色的线

    UISearchBar*searchBar =self.searchController.searchBar;

    UIImageView*barImageView = [[[searchBar.subviewsfirstObject]subviews]firstObject];

    barImageView.layer.borderColor= [UIColor grayColor].CGColor;

     barImageView.layer.borderWidth=1;

    self.tableView.tableHeaderView = searchBar;

    3.searchBar加到tableView的headerView上,然后为tableView添加sectionIndex,tableView整体左移,searchBar也一样

    解决方法:

    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, 210)];

    view.backgroundColor= [UIColor whiteColor];

    [view addSubview:searchBar]

    self.tableView.tableHeaderView = view;


    相关文章

      网友评论

          本文标题:UISearchController好用,但是要避过这些坑

          本文链接:https://www.haomeiwen.com/subject/ufcopftx.html