Why is this UISearchBar getting resized?

前端 未结 2 861
不知归路
不知归路 2021-02-09 11:40

As shown below, my UISearchBar is getting resized when I tap on the search field. It animates nicely to cover the navigation bar, and then pop... it shrinks.

<
2条回答
  •  悲&欢浪女
    2021-02-09 12:14

    Following on from what both @TimothyMoose and @hpique have said about setting translatesAutoresizingMaskIntoConstraints = YES (yuck)

    In my code I have found that if I do the following to show the searchDisplayController

    self.searchDisplayController.searchBar.translatesAutoresizingMaskIntoConstraints = YES
    [self.searchDisplayController setActive:YES animated:YES] 
    

    and do the opposite when closing the searchDisplayController,

    self.searchDisplayController.searchBar.translatesAutoresizingMaskIntoConstraints = NO
    [self.searchDisplayController setActive:NO animated:YES] 
    

    Then my view remains unchanged (everything goes back to what I'm expecting)

    if i do not call the following line when closing

    self.searchDisplayController.searchBar.translatesAutoresizingMaskIntoConstraints = NO
    

    Then the view screws up.

    The reason for this I believe is that the NSAutoresizingMaskLayoutConstraint are asserting them self and as they are the last in the constraint list, the Layout engine brakes the real constraint to satisfy the unwanted NSAutoresizingMaskLayoutConstraint constraints.

提交回复
热议问题