Programing

테이블 헤더보기에서 UISearchController가 표시하는 UISearchBar가 활성화되면 너무 멀리 애니메이션됩니다.

lottogame 2020. 12. 28. 07:42
반응형

테이블 헤더보기에서 UISearchController가 표시하는 UISearchBar가 활성화되면 너무 멀리 애니메이션됩니다.


UISearchController를 사용하여 tableview의 헤더보기 내에 검색 창을 표시하고 있습니다.

...
self.searchController.hidesNavigationBarDuringPresentation = NO;            
self.presentingTVC.tableView.tableHeaderView = self.searchController.searchBar;
[self.searchController.searchBar sizeToFit];
self.presentingTVC.tableView.tableHeaderView = self.searchController.searchBar;

(여기서 tableHeaderView 속성을 두 번 설정해야합니다. 그렇지 않으면 헤더 뷰가 첫 번째 행과 겹치므로 SO에 대한 몇 가지 답변 참조)

비활성 상태 일 때 완벽하게 제자리에있는 모습입니다. 올바른 위치에 비활성 검색 창

검색 창은 활성 상태 일 때 그대로 유지되어야합니다. 탐색 모음을 숨기기 위해 위로 이동하고 싶지 않습니다. 하지만 예상치 않게 아래로 애니메이션이 적용되어 탐색 막대와 빈 공간이 남습니다.

너무 아래로 애니메이션 된 검색 창을 보여주는 스크린 샷

여기의 이상한 검색 창 애니메이션의 비디오

UISearchController와 별도로 검색 창을 사용하면 활성화 될 때 동일한 동작이 표시되지 않습니다.

내 제시 뷰 컨트롤러, 나는이 self.definesPresentationContext = YES;self.navigationController.navigationBar.translucent = YES;하고 "연장 가장자리"의 IB 없음에 상자 (모든 주위를 읽고, 검색 프리젠 테이션을 던질 수있는 가능한 일이 될 듯) 활성화됩니다.

누구든지 검색 창이 아래로 움직이는 것을 막을 수있는 방법을 알고 있습니까?


그래서 마침내 해결책을 찾았습니다. 코드 / 스토리 보드에 다른 것들이있을 가능성이 높지만 (그래서 대답하기 어려운 질문입니다) 대부분의 경우 UISearchController에 대한 Apple의 튜토리얼을 따랐습니다. ( https://developer.apple.com/library/ ios / samplecode / TableSearch_UISearchController / Introduction / Intro.html )

내 코드는 거의 모두 동일하지만 내부를 클릭 할 때 검색 창이 점프하지 않도록 할 수 없습니다. 그래서 제가 한 것은 스토리 보드의 원본 테이블보기와 검색 결과 테이블보기 모두에 대해 "불투명 막대 아래"를 확인하는 것입니다. 점프를 멈출 수있는 검색 창이 생겼습니다.

그러나 마지막 문제가 하나 있었는데, 결과 테이블보기의 첫 번째 행이 검색 창에 의해 숨겨 졌다는 사실이었습니다. 이를 수정하기 위해 결과 테이블보기 방법에 추가 self.tableView.contentInset = UIEdgeInsetsMake(kHeightOfTableViewCells, 0, 0, 0);했습니다 viewDidLoad. 짜잔!


이전 질문이지만 설정하여이 문제를 해결할 수있었습니다.

self.extendedLayoutIncludesOpaqueBars = YES;

내 뷰 컨트롤러에서. 불투명 한 내비게이션 바가 있지만 검색 컨트롤러에서로 설정 hidesNavigationBarDuringPresentation하여 NO초점을 맞출 때 검색 바가 잘못 배치 되어 문제가 발생한다고 생각 합니다.


UISearchBar내 ViewController에서 다음 줄을 제거하여 아래로 이동 하는 것을 방지 할 수있었습니다 .self.definesPresentationContext = YES;


definePresentationContext = 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

내 차례. WWDC 샘플 코드를 따랐을 때도이 문제가 발생했습니다.

searchBar의 scopeButtonTitles 속성을 설정하지 않으면 searchBar가 표시되지 않습니다. 자세히 살펴보면 CGRectZero 프레임이있었습니다. 즉, scopeButtonTitles를 설정하면 장면 뒤의 프레임이 설정됩니다. 따라서 scopeButtonTitles를 표시하고 싶지 않지만 UISearchBar를 특정 높이로 하드 코딩하지 않으려면 scopeButtonTitles를 빈 배열로 설정하십시오.

self.searchController = UISearchController(searchResultsController: nil)
self.searchController.searchResultsUpdater = self
self.searchController.searchBar.scopeButtonTitles = []
self.tableView.tableHeaderView = self.searchController.searchBar

scopeButtonTitles를 1 개의 문자열 배열로 설정하면 스코프 버튼 제목이 표시되지 않지만 뷰를 처리하는 로직이있어 기본적으로 레이아웃이 망가집니다.

Props to Apple's QA team (applicable to iOS 8)


I ran to this problem just recently and none of the solutions worked for me. Maybe because my UI is more complex (My table view with search supports in contained in UITabController inside a UiNavigationController) anyway, none of the above worker. I could simply solve my problem by this very neat piece of code I found at: UISearchController Not Redisplaying Navigation Bar on Rotate

- (UIBarPosition)positionForBar:(id<UIBarPositioning>)bar
{
    if (bar == searchController.searchBar) {
        return UIBarPositionTopAttached;
    }
    else { // Handle other cases
        return UIBarPositionAny;
    }
}

One more thing to add: after setting all my controller's hierarchy to extend under opaque and top bars, my search bar started to appear hidden under navigation bar and would've appeared right just after a rotation might happened. that was a cue for me that there is some lay out error and some information abut my layout was not right. this delegate method helps my controller understand the situation about the otherwise nomad search bar!


Found it! This seems to be the offensive line in viewDidLoad of the presenting vc:

self.edgesForExtendedLayout = UIRectEdgeNone;

Removed that and the search bar stayed in place as predicted.


unchecking Adjust Scroll View Insets

and

checking Under Top Bars

Fixed my problem여기에 이미지 설명 입력


for iOS 11 & swift 4, set the line bellow in the viewController resolved my issue (searchBar jump down):

self.edgesForExtendedLayout = .bottom

I guess you set UISearchBar frame.original.y = 64

there are the code

if ([self respondsToSelector:@selector(setEdgesForExtendedLayout:)]) {
    [self setEdgesForExtendedLayout:UIRectEdgeNone];
}

searchBar.frame = CGRectMake(0, 0, 376, 44);

wash can help you


In my case, setting the nav bar to self.navigationController.navigationBar.translucent = NO; fixed the problem. It seems that the search bar presentation layer doesn't take into account the translucence of the nav bar when laying out the search bar.

I realize this isn't a perfect solution, because the translucence of the nav bar can throw off layout elsewhere, but it at least fixes the problem in the case where a non-translucent nav bar is a possibility.


As mentioned in the first post everyone needed a different solution. So here is mine. I had to combine two things mentioned on this page, namely:

Swift 2:

    navigationController?.navigationBar.translucent = true

    edgesForExtendedLayout = .None

its very simple just do clipsToBounds = true of header view of table view in witch search bar is added.

countryTableView.tableHeaderView?.clipsToBounds = true

당신이 사용하는 경우 UINavigationController그리고 TabBar당신은 할 수 사용

self.extendedLayoutIncludesOpaqueBars = true

이 솔루션이 필요합니다 : https://stackoverflow.com/a/46151063/3369381

참조 URL : https://stackoverflow.com/questions/28326269/uisearchbar-presented-by-uisearchcontroller-in-table-header-view-animates-too-fa

반응형