2017-04-13 74 views
0

我有一個嵌套在另一個NSScrollView中的NSScrollView應用程序。我希望用戶能夠使用雙指滑動滾動內部滾動視圖,並使用三個手指滾動外部滾動視圖。可以使用不同手勢滾動的嵌套NSScrollView?

我想我會需要以某種方式配置每個滾動視圖拒絕與錯誤的手指數量觸摸,但我不知道如何做到這一點。

回答

0

我想通了!訣竅在於內部ScrollView的子類並強制它拒絕具有一定觸摸次數的手勢,並將它們轉發到父滾動視圖:

- (void)scrollWheel:(NSEvent *)event { 
    if (_forwardScrollToParent) { 
     // [self.enclosingScrollView scrollWheel:event]; 
    } else { 
     [super scrollWheel:event]; 
     [self recordInteractionWithThisTab]; 
    } 
} 

- (void)touchesBeganWithEvent:(NSEvent *)event { 
    [super touchesBeganWithEvent:event]; 
    NSInteger nTouches = [event touchesMatchingPhase:NSTouchPhaseTouching inView:self].count; 
    if (nTouches == 3) { 
     _forwardScrollToParent = YES; 
    } else { 
     _forwardScrollToParent = NO; 
    } 
} 
- (void)scrollWheel:(NSEvent *)event { 
    if (_forwardScrollToParent) { 
     // [self.enclosingScrollView scrollWheel:event]; 
    } else { 
     [super scrollWheel:event]; 
     [self recordInteractionWithThisTab]; 
    } 
} 

- (void)touchesBeganWithEvent:(NSEvent *)event { 
    [super touchesBeganWithEvent:event]; 
    NSInteger nTouches = [event touchesMatchingPhase:NSTouchPhaseTouching inView:self].count; 
    if (nTouches == 3) { 
     _forwardScrollToParent = YES; 
    } else { 
     _forwardScrollToParent = NO; 
    } 
}