title: UISearchController expands off screen when tapped
body: <p>We're having a weird issue with using a UISearchController as an item in a navigation bar. It's set as the left bar button item and when a user taps to start searching, the search bar expands to the right off the side of the screen.</p>
  
  <p>Below is the code for creating the UISearchController:</p>
  
  <pre><code>resultSearchController = ({
      let controller = UISearchController(searchResultsController: nil)
      controller.searchResultsUpdater = self
      controller.dimsBackgroundDuringPresentation = false
      controller.hidesNavigationBarDuringPresentation = false
      controller.searchBar.delegate = self
      controller.delegate = self
  
      controller.searchBar.frame = CGRect(x: 0, y: 0, width: 266, height: 44.0)
      let searchBarView = UIView(frame: controller.searchBar.frame)
      searchBarView.addSubview(controller.searchBar)
  
      controller.searchBar.backgroundImage = UIImage(named: "searchBarBG")
      controller.searchBar.barTintColor = .white
      controller.searchBar.subviews[0].subviews.flatMap(){ $0 as? UITextField }.first?.tintColor = Constants.Colors.Red
  
      navigationItem.leftBarButtonItem = UIBarButtonItem(customView: searchBarView)
  
      return controller
  })()
  </code></pre>
  
  <p>When the screen first loads, it looks like <a href="https://i.imgur.com/mTW1CqD.png" rel="nofollow noreferrer">this.</a></p>
  
  <p>After tapping on the search bar, it changes to look like <a href="https://i.imgur.com/1GFQm2m.png" rel="nofollow noreferrer">this.</a></p>
  
  <p>I have no idea what's causing this. After lots of searching, I tried changing <code>self.definesPresentationContext = false;</code> and <code>self.extendedLayoutIncludesOpaqueBars = true</code> as well as adjusting similar checkboxes in the storyboard. Any tips?</p>
  
  <p><strong>Edit:</strong> This only seems to happen on iOS 11. In 10.3, the search bar actually shrinks a little to accommodate the Cancel button but ultimately takes up the same amount of space.</p>