UITableView content overlaps Status Bar when UISearchBar is active

后端 未结 8 585
北海茫月
北海茫月 2021-02-05 02:17

I have a UITableViewController with a UISearchBar and UISearchDisplayController. That exists inside a Container View in a UIViewController which is in a UINavigationController.

相关标签:
8条回答
  • 2021-02-05 03:09

    Try setting the definesPresentationContext in viewDidLoad of your TableViewController

    Swift

    override func viewDidLoad() {
        super.viewDidLoad()
    
        definesPresentationContext = true
    }
    

    Objective-C

    - (void)viewDidLoad {
        [super viewDidLoad];
    
        self.definesPresentationContext = YES;
    }
    
    0 讨论(0)
  • 2021-02-05 03:15

    Basically this is due to the traslucency of the nav bar, usually the view controller fix that overlapping, by correcting the top insets of the owned view or subview if they are(or inherits) from UIScrollView. You have 2 options, one is to set the traslucency of the navbar to no, the other is set the edgeForExtendedLayout to none ore leave only bottom.

    - (void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller {
        self.navigationController.navigationBar.translucent = YES;
    }
    
    - (void)searchDisplayControllerDidEndSearch:(UISearchDisplayController *)controller {
        self.navigationController.navigationBar.translucent = NO;
    }
    

    These advices works only on iOS7, if you are deploying on lower target check before settings those properties.
    Another way around, but I didn't tested could be read the --topLayoutGuide length and in the -searchDisplayControllerWillBeginSearch try to set a topInsets of the same length. In this way you should still preserve the translucency.

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