Wrong active SearchBar position within custom container view controller

Originator:stefan.lorenz.pauwels
Number:rdar://27024192 Date Originated:27-Jun-2016
Status:Open Resolved:
Product:iOS SDK Product Version:
Classification: Reproducible:Always
 
Summary:
Situation: 
- A childViewController in a custom container view controller. The childViewController's view is inset a bit and does not fully fill the container.
- The childViewController is a UITableViewController with a searchBar as tableHeaderView

Effect: The searchBar is displayed correctly when not active. But it moves to a wrong position (to the right) immediately after tapping into the search text field. It seems like the superfluous x inset of the active searchBar equals the inset of the childViewController itself.

See the attached sample project.

Steps to Reproduce:
1. In Xcode, create new Swift-based Project of the type "Single View Application"
2. Change the auto-generated ViewController.swift to the code below
3. Run in iPad Simulator to see the effect best
4. Tap into searchbar

class ViewController: UIViewController {
    let searchController = UISearchController(searchResultsController: nil)

    override func viewDidLoad() {
        super.viewDidLoad()
    
        let childViewController = UITableViewController(style: .grouped)
        childViewController.tableView.tableHeaderView = searchController.searchBar
        childViewController.definesPresentationContext = true
        childViewController.view.frame = self.view.frame.insetBy(dx: 100, dy: 100)

        self .addChildViewController(childViewController)
        self.view.addSubview(childViewController.view)
        childViewController.didMove(toParentViewController: self)
    }
}


Expected Results:
SearchBar control as a whole should stay in place (I am aware that parts - the textfield and cancel button - have to move around a bit)

Actual Results:
SearchBar control as a whole moves 100 points (= the childViewController's inset) to the right.

Version:
Happens with Xcode 7 and Xcode 8 beta, deployment target iOS 9.3 or iOS 10

Notes:


Configuration:
iPad Air 2 Simulator

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!