Потяните, чтобы показать UISearchController, добавленный в качестве подпредставления UICollectionReusableView, используемого в качестве заголовка раздела UICollectionView. - PullRequest
0 голосов
/ 23 октября 2018

Я пытаюсь использовать contentOffset, чтобы скрыть UISearchController, добавленный в качестве подпредставления UICollectionView, используемого в качестве заголовка раздела UICollectionView в строках следующего ответа для UITableView: https://stackoverflow.com/a/7619749/7271020

var searchController = UISearchController(searchResultsController: nil)
override func viewDidLoad() {
    super.viewDidLoad()
    collectionView.contentOffset = CGPoint(x: 0, y: searchController.searchBar.frame.height)
}

Заголовокпредставление зарегистрировано с помощью метода делегата CollectionView:

func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {

    if (kind == UICollectionView.elementKindSectionHeader) {
        let headerView:UICollectionReusableView =  collectionView.dequeueReusableSupplementaryView(ofKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: "CollectionViewHeader", for: indexPath)

        headerView.addSubview(searchController.searchBar)

        return headerView
    }

    return UICollectionReusableView()
}

Я хочу иметь возможность скрыть UICollectionReusableView для начала и открыть его только тогда, когда пользователь закрывает UICollectionView.Как этого добиться?

...