Prevent a UISearchDisplayController from hiding the navigation bar

后端 未结 15 1661
南方客
南方客 2020-11-27 11:59

Whenever a user begins editing a UISearchDisplayController\'s search bar, the search controller becomes active and hides the view\'s navigation bar while presen

15条回答
  •  不知归路
    2020-11-27 12:11

    iOS 7 screws things up a bit... for me this worked perfectly:

    /**
     *  Overwrite the `setActive:animated:` method to make sure the UINavigationBar 
     *  does not get hidden and the SearchBar does not add space for the statusbar height.
     *
     *  @param visible   `YES` to display the search interface if it is not already displayed; NO to hide the search interface if it is currently displayed.
     *  @param animated  `YES` to use animation for a change in visible state, otherwise NO.
     */
    - (void)setActive:(BOOL)visible animated:(BOOL)animated
    {
        [[UIApplication sharedApplication] setStatusBarHidden:YES];
        [self.searchContentsController.navigationController setNavigationBarHidden:YES animated:NO];
    
        [super setActive:visible animated:animated];
    
        [self.searchContentsController.navigationController setNavigationBarHidden:NO animated:NO];
        [[UIApplication sharedApplication] setStatusBarHidden:NO];
    }
    

    The reason for show/hide the statusbar

提交回复
热议问题