The search bar in the navigation element crashes and gets stuck under the status bar when navigating the navigation, on iOS 11

I am using the new property of the iOS 11 searchContollerproperty UINavigationItem. I am running the build of iOS 11.0 GM.

When I execute a push sega while the active search controller is active, it works fine. When I jump back again, the search bar crashes and shrinks in the status bar. I cannot cancel the search or change the search text.

See the following image sequence:

The initial state of the table Filtered table with search Collapsed default search string

pop segue . , . 90% , . , -, . , , .

, , . viewDidLoad() :

searchController = UISearchController(searchResultsController: nil)
searchController.dimsBackgroundDuringPresentation = false
searchController.searchBar.returnKeyType = .done
searchController.searchBar.placeholder = "Your Library"
searchController.searchBar.searchBarStyle = .minimal

// We will manage the clearing of selections ourselves.
clearsSelectionOnViewWillAppear = false

// Some search bar styles are slightly different on iOS 11
if #available(iOS 11.0, *) {
    navigationItem.searchController = searchController
    navigationController!.navigationBar.prefersLargeTitles = true
}
else {
    searchController.searchBar.backgroundColor = tableView.backgroundColor!
    searchController.hidesNavigationBarDuringPresentation = false
    tableView.tableHeaderView = searchController.searchBar
    tableView.setContentOffset(CGPoint(x: 0, y: searchController.searchBar.frame.height), animated: false)
}

Apple Messages (. ), "", "" "", , , IOS 11.

Application search bar crushed in pop

→ → → , ( ). viewDidAppear, searchController.searchBar.frame.height 0 ( viewDidDisappear, viewWillAppear). , :

override func viewDidAppear(_ animated: Bool) {
    if #available(iOS 11.0, *), searchController.searchBar.frame.height == 0 {
        navigationItem.searchController?.isActive = false
    }

    super.viewDidAppear(animated)
}

?

+4
1

iOS 11.1:

- (void)viewDidLoad {
    [super viewDidLoad];

    self.navigationItem.hidesSearchBarWhenScrolling = NO;
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];

    if (@available(iOS 11.0, *)) {
        self.navigationItem.hidesSearchBarWhenScrolling = YES;
    }
}

mutate navigationItem VC, ​​

0

Source: https://habr.com/ru/post/1685744/


All Articles