2014-07-10 5 views
0

해당보기의 단추를 누르면 표준 VC 안에 검색 막대를 추가하고 싶습니다.UIButton을 탭하면 검색 막대를 표시하는 방법

이 작업을 수행하는 간단하고 우아한 방법이 있습니까? 프로그래밍 방식으로 생성해야한다고 생각하지만 애니메이션을 전환 표시에 추가하고 숨길 수있는 멋진 솔루션을 모릅니다.

답변

0

프로그램의 작성 아래 시도 : -

UISearchBar *searchBar = [[UISearchBar alloc] 
    initWithFrame:CGRectMake(0, 70, 320, 44)]; 


    //Now add in your view once you click on 
    button 
    [self.view addSubView:searchBar]; 
5

먼저 선언 객체를 ViewController.h

@interface ViewController() 
{ 
    UISearchBar *searchBar; 
} 
@end 

에 설정된 프레임보다 ViewController.m의있는 viewDidLoad에서 :

searchBar = [[UISearchBar alloc]initWithFrame:CGRectMake(0,0, 320, 44)]; 

searchBar.Hidden=YES; 

지금 버튼에 애니메이션 추가 :

- (IBAction)btnEvent:(id)sender 
{ 
    searchBar.Hidden=NO; 
    [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide]; 
    [UIView animateWithDuration:0.25 animations:^{ 
      searchBar.frame = CGRectMake(0, 20, 320, 44); 
      [self.view addSubview:searchBar]; 
    }]; 
} 
관련 문제