2012-06-07 2 views
3

내가 가지고있는 뷰의 다음과 같은 구조에서의 UIView 그러나 hitTest 블록은 전망

UIView(1) 
    |--> UIScrollView 
     |-----------> UIView(2) 
         |------> UIButton 

그러나 hitTest 의 UIView (1) 다음을로 대체되었습니다

- (UIView *)hitTest:(CGPoint) point withEvent:(UIEvent *)event 
{ 
    /* this view should have only view only: the scroll view */ 
    UIView * vv = [[self subviews] objectAtIndex:0]; 

    if ([vv pointInside:point withEvent:event]) 
    { 
     UIView *rv = [vv hitTest:point withEvent:event]; 
     return rv; 
    } 

    if ([self pointInside:point withEvent:event]) 
    { 
     return vv; 
    } 
    return nil; 
} 

이가 필요합니다 UIScrollView 스크롤 뷰 자체 외부로 끌기 위해

UIButton을 클릭하면 해당 이벤트에 연결된 이벤트가 실행되지 않습니다. hitTest에서 반환 된보기는 이며 UIView (2)입니다.

UIButton을 클릭 이벤트에 응답하려면 어떻게해야합니까? 의 제안 문디

편집 , 나는 다음과 같이 그러나 hitTest를 교환하고 그것을 작동합니다. 물론, 나는 [super hitTest :]에게 전화하는 것을 잊었다.

- (UIView *)hitTest:(CGPoint) point withEvent:(UIEvent *)event 
{ 
    /* this view should have only view only: the scroll view */ 
    UIView * scrv = [self findScrollView]; 

    UIView *superView = [super hitTest:point withEvent:event]; 
    if (superView == self) 
    { 
     return scrv; 
    } 

    return superView; 
} 

답변

3

적절한 시점에 [super hitTest:point withEvent:event]을 호출하는 것은 어떻습니까?