UISearchBar animation issue

后端 未结 8 1193
迷失自我
迷失自我 2020-12-08 11:22

I have a UIViewController in which I want to show a tableview with the serchBar.

//viewDidLoad
_tableView = [[UITableView alloc] initWithFrame:CGRectMake(0,
          


        
相关标签:
8条回答
  • 2020-12-08 11:56

    In your Storyboard, select the problematic controller, look at the Attributes tab and try to edit these settings:

    • Under Top Bars
    • Under Opaque Bars

    I've solved a similar problem by unflagging these settings.

    0 讨论(0)
  • 2020-12-08 11:57

    I found what is causing this issue. Seems that the animation gets messed up when you set navigationBar.translucent to NO. If you make your navigationBar translucent, everything should work fine, but this is definitely not an ideal solution. I'm going to try and find a workaround.

    0 讨论(0)
  • 2020-12-08 11:59

    You can cancel animation by subclassing UISearchDisplayController and adding this:

    - (void)setActive:(BOOL)visible animated:(BOOL)animated
    {
         if(self.active == visible) return;
         [self.searchContentsController.navigationController setNavigationBarHidden:YES animated:NO];
         [super setActive:visible animated:animated];
         [self.searchContentsController.navigationController setNavigationBarHidden:NO animated:NO];
         if (visible) {
              [self.searchBar becomeFirstResponder];
         } else {
              [self.searchBar resignFirstResponder];
         }
    }
    
    0 讨论(0)
  • 2020-12-08 12:15

    As a reminder for anyone with similar issues. I needed to add this line that fixed things:

    self.edgesForExtendedLayout = UIRectEdgeNone;
    
    0 讨论(0)
  • 2020-12-08 12:15

    Why are you creating the searchBar programmatically instead of in the StoryBoard ? I'm currently using searchBar, added in storyboard and it's work fine ( I have to change the contentOffset )

    0 讨论(0)
  • 2020-12-08 12:20
    UITableView *_tableView = [[UITableView alloc] initWithFrame:CGRectMake(0,
                                                               64,
                                                               self.view.frame.size.width,
                                                               self.view.frame.size.height)
                                              style:UITableViewStylePlain];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    
    [self.view addSubview:_tableView];
    
    // adding uisearch bar
    UISearchBar* searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
    
    _tableView.tableHeaderView = searchBar;
    
    
    
    //
    UISearchDisplayController* searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self];
    searchDisplayController.delegate = self;
    searchDisplayController.searchResultsDataSource = self;
    

    and I just embade my controller with UINavigationcontroller and its working quite well..enter image description here

    0 讨论(0)
提交回复
热议问题