2014-01-18 2 views
1

나는 UINavigationBar, UITabBarUITableView을 가지고 UIView입니다. TRUE으로 설정했기 때문에 상태 표시 줄을 누르면 UITableView이 맨 위로 스크롤됩니다.UITableview 스크롤 위로 UINavigationbar를 누르는

일부 응용 프로그램에서 발생하는 것처럼 UINavigationBar을 눌러 동일한 작업을 수행 할 수 있기를 원합니다. UITableViewscrollsToTop = TRUE으로 설정하면 사용자가 StatusBar을 누르면 작동합니다.

답변

2

방법 1 :

어떻게 UINavigationBarTapGestureRecogniser을 추가하는 방법에 대한? 이것은 네비게이션 바에 버튼이 없다면 작동합니다.

//Create a tap gesture with the method to call when tap gesture has been detected 
UITapGestureRecognizer* tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(navBarClicked):]; 

//isolate tap to only the navigation bar 
[self.navigationController.navigationBar addGestureRecognizer:tapRecognizer]; 

//same method name used when setting the tapGesure's selector 
-(void)navBarClicked:(UIGestureRecognizer*)recognizer{ 
    //add code to scroll your tableView to the top. 
} 

그게 전부입니다.

  1. 방법 2 :

    어떤 사람들

    자신의 뒤로 가기 버튼이 탐색 모음에 탭 제스처를 추가 할 때이 두 가지 중 하나를 수행 할 수 있도록 작동이 중지 것으로 나타났습니다에 사용할 사용자 상호 작용을 설정 예 및 탭 제스처 인식기를 방법 2와 같이 자세하게 설정하십시오.
  2. 방법 3 : gestureRecognizer:shouldReceiveTouch이라는 UIGestureRecognizerDelegate 메서드를 사용하고 터치보기가 단추 인 경우 NO을 반환하고 그렇지 않으면 YES을 반환하십시오. 방법 3을 자세히보십시오. 포인트 1

방법 2 : -

[[self.navigationController.navigationBar.subviews objectAtIndex:1] setUserInteractionEnabled:YES]; 
[[self.navigationController.navigationBar.subviews objectAtIndex:1] addGestureRecognizer:tapRecognizer]; 

방법 3 점 2에서 hackish/더러운 느낌 : - 훨씬 더, 올바른 방법

UIGestureRecognizerDelegate 프로토콜을 구현 .h 파일과 .m 파일에 다음을 추가하십시오.

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch { 

    // Disallow recognition of tap gestures when a navigation Item is tapped 
    if ((touch.view == backbutton)) {//your back button/left button/whatever buttons you have 
     return NO; 
    } 
    return YES; 
} 
관련 문제