Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 11 UISearchBar in navigation bar

The UISearchBar behaves different in iOS 11 then in iOS 10 and below.

  • the size has changed
  • the fade-out animation when pushing another view controlled is missing

I handled to "fix" the size somehow with this code:

if #available(iOS 11.0, *) {
    searchBar.heightAnchor.constraint(equalToConstant: 44).isActive = true
}

But I can't fix the animation. Any ideas, apart from just animating the search bar manually on push?

UIView.animate(withDuration: 0.3, animations: { [weak self] in
    guard let strongSelf = self else { return }
    strongSelf.searchBar.alpha = 0.0
})

See a video of the broken animation effect here.

like image 324
Darko Avatar asked Sep 04 '17 13:09

Darko


2 Answers

Just wrap it with a UIView, and the animation comes back.

like image 175
awuu Avatar answered Nov 19 '22 04:11

awuu


Look answer in UIPercentDrivenInteractiveTransition. It's using for update UIViews during UINavigationController transition in persentage value.

Other words, depends on how much UINavigationController already opened next view controller or move backwards views will have different appearance.

This value will help you update your search bar (alpha, width, etc.)

like image 22
ObranS Avatar answered Nov 19 '22 05:11

ObranS