2012-09-06 4 views
6

누구나 UIToolbar의 UIBarButtonItem 인 UISearchDisplayArroller를 사용하여 UISearchDisplayController를 사용해 보았습니까?iOS - UIToolbar에서 UIBarButtonItem 인 UISearchDisplayController를 사용합니다.

이 작업을 성공적으로 수행하는 방법에 대한 도움말을 보내 주시면 감사하겠습니다. 검색 컨트롤러는하지만, 그것은 UISearchBar 다시 그려 나는 보통 도구 모음 내부 검색 창을 넣어하지 않을 UIToolbar

+0

그래서 .. UISearchBar를 사용자 정의 하시겠습니까? 그게 질문입니까? –

+0

두 가지 질문이 있습니다. 1. UISearchDisplayController를 첨부 할 경우 UIToolbar에 UISearchBar를 포함하지 않아야합니까? 2. UISearchDisplayController에서 UISearchBar의 모양을 수정하면 어떻게 활성화됩니까? 현재 재 묘화되고 재배치되었으며 UIToolbar에서 UISearchBar의 모양을 유지하지 않습니다. – Rammeln

답변

5

와 비슷한 모양을 유지하기 위해 사투를 벌인거야 팝업 현재 때마다

, 그것은 내가 한 일과 비슷한 것을하고 싶다. 그래서 여기

내가 그것을 어떻게했는지, 그것은 해킹 호출 할 수있다, 그러나 당신이이 같은 인터페이스 빌더에서 그것을 설정해야 매력 :

처음처럼 작동 :

enter image description here

검색이 도구 모음의 자식이 아니라 위의 내용임을 유의하십시오.

검색 표시 줄에는 "선명한 색상"의 배경과 유연한 왼쪽, 오른쪽 및 너비 자동 크기 조정 마스크가 있어야합니다.

검정색 배경이있는 1 픽셀 레이블을 도구 모음 아래에 놓습니다. [x = 0, y = 44, width = 320 또는 frame width, height = 1], 또한 유연한 왼쪽, 오른쪽 및 너비 자동 크기 조정 마스크를 사용합니다. 검색 디스플레이 컨트롤러가 테이블을 표시 한 후 전망. 그것이 의미하는 바를 이해하지 않고 그것을 시도하십시오.

도구 모음 항목을 설정하고 필요할 때 도구 모음 항목이 있는지 확인하십시오.

- (void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller 
{ 
    // animate the search bar to the left ie. x=0 
    [UIView animateWithDuration:0.25f animations:^{ 
     CGRect frame = controller.searchBar.frame; 
     frame.origin.x = 0; 
     controller.searchBar.frame = frame; 
    }]; 
    // remove all toolbar items 
    [self.toolbar setItems:nil animated:YES]; 
} 

내가이 멋진 애니메이션을 다음 얻을이와

- (void)searchDisplayControllerDidEndSearch:(UISearchDisplayController *)controller 
{ 
    // animate search bar back to its previous position and size 
    // in my case it was x=55, y=1 
    // and reduce its width by the amount moved, again 55px 
    [UIView animateWithDuration:0.25f 
          delay:0.0f 
         // the UIViewAnimationOptionLayoutSubviews is IMPORTANT, 
         // otherwise you get no animation 
         // but some kind of snap-back movement 
         options:UIViewAnimationOptionLayoutSubviews 
        animations:^{ 
         CGRect frame = self.toolbar.frame; 
         frame.origin.y = 1; 
         frame.origin.x = 55; 
         frame.size.width -= 55; 
         controller.searchBar.frame = frame; 
        } 
        completion:^(BOOL finished){ 
         // when finished, insert any tool bar items you had 
         [self.toolbar setItems:[NSArray arrayWithObject:self.currentLocationButton] animated:YES]; 
        }]; 
} 

을 검색 종료 :

당신이 검색을 시작

코드 이제

... :)

enter image description here

enter image description here

관련 문제