UISearchBar presented by UISearchController in table header view animates too far when active

后端 未结 15 1023
长情又很酷
长情又很酷 2020-11-29 01:28

I am using UISearchController to present a search bar inside the header view of a tableview:

...
self.searchController.hidesNavigationBarDuringPresentation =         


        
相关标签:
15条回答
  • 2020-11-29 01:49

    I ran to this problem just recently and none of the solutions worked for me. Maybe because my UI is more complex (My table view with search supports in contained in UITabController inside a UiNavigationController) anyway, none of the above worker. I could simply solve my problem by this very neat piece of code I found at: UISearchController Not Redisplaying Navigation Bar on Rotate

    - (UIBarPosition)positionForBar:(id<UIBarPositioning>)bar
    {
        if (bar == searchController.searchBar) {
            return UIBarPositionTopAttached;
        }
        else { // Handle other cases
            return UIBarPositionAny;
        }
    }
    

    One more thing to add: after setting all my controller's hierarchy to extend under opaque and top bars, my search bar started to appear hidden under navigation bar and would've appeared right just after a rotation might happened. that was a cue for me that there is some lay out error and some information abut my layout was not right. this delegate method helps my controller understand the situation about the otherwise nomad search bar!

    0 讨论(0)
  • 2020-11-29 01:50

    for iOS 11 & swift 4, set the line bellow in the viewController resolved my issue (searchBar jump down):

    self.edgesForExtendedLayout = .bottom
    
    0 讨论(0)
  • 2020-11-29 01:51

    unchecking Adjust Scroll View Insets

    and

    checking Under Top Bars

    Fixed my problem

    0 讨论(0)
  • 2020-11-29 01:51

    I guess you set UISearchBar frame.original.y = 64

    there are the code

    if ([self respondsToSelector:@selector(setEdgesForExtendedLayout:)]) {
        [self setEdgesForExtendedLayout:UIRectEdgeNone];
    }
    
    searchBar.frame = CGRectMake(0, 0, 376, 44);
    

    wash can help you

    0 讨论(0)
  • 2020-11-29 01:53

    its very simple just do clipsToBounds = true of header view of table view in witch search bar is added.

    countryTableView.tableHeaderView?.clipsToBounds = true
    
    0 讨论(0)
  • 2020-11-29 01:54

    Old question but I was able to solve this issue by setting

    self.extendedLayoutIncludesOpaqueBars = YES;

    on my view controller. I think is issue is caused by having an opaque navigation bar but setting hidesNavigationBarDuringPresentation to NO on your search controller, causing the search bar to incorrectly position itself when focused.

    0 讨论(0)
提交回复
热议问题