title: UISearchBar automatically resizes and changes frame
body: <p>I have an issue with a search bar that behaves in a strange way when it becomes a <code>firstResponder</code> and when it resigns.</p>
  
  <p>The search bar is added as the header of a table view</p>
  
  <pre><code>self.searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0.0f, 0.0f, self.view.frame.size.width, 44.0f)];
  self.searchBar.translucent = NO;
  self.searchBar.barTintColor = [UIColor grayColor];
  self.tableView.tableHeaderView = self.searchBar;
  
  self.searchController = [[UISearchDisplayController alloc] initWithSearchBar:self.searchBar
                                                            contentsController:self];
  self.searchController.searchResultsDataSource = self;
  </code></pre>
  
  <p>The view controller is set a left panel of <a href="https://github.com/gotosleep/JASidePanels" rel="noreferrer"><code>JASidePanelController</code></a> and it hides the center panel when the keyboard shows or hides :</p>
  
  <pre><code>- (void)keyboardWillAppear:(NSNotification *)note
  {
      [self.sidePanelController setCenterPanelHidden:YES
                                            animated:YES
                                            duration:[[note.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue]];
      self.searchBar.showsCancelButton = YES;
  }
  
  - (void)keyboardWillDisappear:(NSNotification *)note
  {
      [self.sidePanelController setCenterPanelHidden:NO
                                            animated:YES
                                            duration:[[note.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue]];
      self.searchBar.showsCancelButton = NO;
  }
  </code></pre>
  
  <p>Normal state 
  <img src="https://i.stack.imgur.com/O58Zc.png" alt="Normal state">
  <br><br>
  When the search bar becomes a <code>firstResponder</code> it either moves about a point up or point down randomly</p>
  
  <p><img src="https://i.stack.imgur.com/Dprcm.png" alt="Point up">
  <img src="https://i.stack.imgur.com/Ce6io.png" alt="Point down"></p>
  
  <p><br><br>
  And When the search bar resigns it animates up to reach the window origin and then back to its natural frame</p>
  
  <p><img src="https://i.stack.imgur.com/7rrGZ.png" alt="Stretching up"></p>
  
  <p><img src="https://i.stack.imgur.com/Pfha2.png" alt="Reaching origin"></p>
  
  <p>Here is a <a href="https://github.com/mouhcine/UISearchBar-bug" rel="noreferrer">sample project</a> reproducing the bug.</p>
  
  <p>EDIT :</p>
  
  <p>As per <a href="https://twitter.com/kwylez" rel="noreferrer">@kwylez</a> <a href="https://twitter.com/kwylez/status/420571416078352385" rel="noreferrer">suggestion</a>, the unwanted animation that the search bar makes when it resigns can be avoided by:</p>
  
  <pre><code>self.searchBar.clipsToBounds = YES;
  </code></pre>