0
votes

I am using the new UISearchController with searchbar inside tableview header.Everything works fine in portrait orientation but when I rotate to landscape and uisearchbar start editing its frame is out of screen,clipping the cancel button. my code for creating searchcontroller

tableView.tableHeaderView = searchController.searchBar

Here is my sample code UISearchController sample

Rotation has no frame issue in landscape but only when uisearchbar starts editing [landscape searchbar

Cancel button clipping

When rotate back to portrait layout of uisearchbar is still incorrectportrait screen after rotating back There is no issue if I use UITableviewController but I have to implement with uitableview.Is there any setting I am missing in iOS 14 ?

Note:I have to use tableHeaderView not navigationItem.searchController = searchController

1
May or may not be a solution for you, but... try constraining the tableView Leading and Trailing to superView instead of safe-area.DonMag
I don't know why you "have to implement with UITableView"? Just use the tools available to you. Why make life difficult for yourself?Abizern
@Abizern uitableview give me more flexibility to add more views to my screen in future.these are old issues that things supporting easily on uitableviewcontroller not working with uitableviewWaseem05
@Waseem05 you can use view controller containment and let the table view controller control the tableview, and you can still add other views (or view controllers) to your main vc.Abizern

1 Answers

-1
votes

Try adjusting the frame of search bar in viewWillTransition method that in your corresponding UIViewController . viewWillTransition is called every time during rotation and enables you to change layout during rotation of your UIViewController.

here is example code:

    override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
    coordinator.animate( alongsideTransition: { (UIViewControllerTransitionCoordinatorContext) -> Void in
        adjustSearchbarFrame()
    }, completion: { (UIViewControllerTransitionCoordinatorContext) -> Void in
    })
    super.viewWillTransition(to: size, with: coordinator)
}