Strange UISearchDisplayController view offset behavior in iOS 7 when embedded in navigation bar

前端 未结 9 953
难免孤独
难免孤独 2020-12-14 03:13

I am building an iOS 7-only app. I am trying to set a UISearchDisplayController into the navigation bar.

I have it set up like this: In the storyboard, I added a \"

相关标签:
9条回答
  • 2020-12-14 03:22

    In my case, using storyboards, I had to check both Under Top Bars and Under Opaque Bars and leave Under Bottom Bars unchecked.

    0 讨论(0)
  • 2020-12-14 03:25

    In my case, I actually had to uncheck all the Extended Edges boxes (essentially the same as programmatically setting Extended Edges to UIRectEdgeNone I believe) in my Storyboard in order to stop my search bar from offsetting itself. Thank you guys!

    0 讨论(0)
  • 2020-12-14 03:25

    My problem was just Adjust scroll view inserts. After change to false I didn't have problem

    0 讨论(0)
  • 2020-12-14 03:25

    I had very similar behavior happening. For me, the solution was to uncheck Extend Edges Under Top Bar in the storyboard settings for the parent view controller (I've turned off transparent navbars, not sure if that effects anything). If you're not using storyboard, you have to set [UIViewController edgesForExtendedLayout].

    From the Apple docs:

    This property is only applied to view controllers that are embedded in containers, such as UINavigationController or UITabBarController. View controllers set as the root view controller do not react to this property. Default value is UIRectEdgeAll.

    0 讨论(0)
  • 2020-12-14 03:28

    definesPresentationContext = true

    override func viewDidLoad() {
            super.viewDidLoad()
    
            searchController = UISearchController(searchResultsController: nil)
            searchController.searchResultsUpdater = self
            searchController.hidesNavigationBarDuringPresentation = false
    
            searchController.dimsBackgroundDuringPresentation = true
            searchController.searchBar.searchBarStyle = UISearchBarStyle.Prominent
            self.tableView.tableHeaderView = searchController.searchBar
    
            definesPresentationContext = true
    

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

    0 讨论(0)
  • 2020-12-14 03:30
    1. Go to storyboard.
    2. Click on the view controller.
    3. Go to attribute inspector under the ViewController section.
    4. Set the Extend Edges section to be Under Top Bars and Under Opaque Bars.
    5. Make sure to un-check Under Bottom Bars.
    0 讨论(0)
提交回复
热议问题